howto:sshkey_google2fa
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | |||
howto:sshkey_google2fa [2025/05/12 21:09] – [ssh-keygen] justip6 | howto:sshkey_google2fa [2025/05/12 21:09] (current) – removed justip6 | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== How to Setup Passwordless SSH-key or Google 2FA NOT BOTH====== | ||
- | |||
- | Below shows two options in securing SSH using Port 22 on Linux machines to enhance security along with ZotDefend. The reason we want to do this is because Port 22 can be opened to the public, not only on the UCI Network. Thus, anyone can try to attempt access to the machine and try to brute force account passwords. | ||
- | |||
- | ===== Setting up Passwordless SSH-key ===== | ||
- | ==== ssh-keygen ==== | ||
- | You use the tool " | ||
- | <code bash> | ||
- | [user@host ~]$ ssh-keygen -t ed25519 -C "Add a Description to easily tell which machine this belongs to" | ||
- | Generating public/ | ||
- | Enter file in which to save the key (/ | ||
- | Enter passphrase (empty for no passphrase): | ||
- | Enter same passphrase: [Enter to leave empty] | ||
- | </ | ||
- | You should leave the default values above by simply hitting Enter three times. | ||
- | |||
- | ==== Distributing your public key ==== | ||
- | The *.pub file needs to be appended to the ~/ | ||
- | <code bash> | ||
- | [user@localhost ~]$ scp ~/ | ||
- | Enter password for user@remotehost: | ||
- | [user@localhost ~]$ ssh user@remotehost | ||
- | Enter Password | ||
- | # That's the last time you'll be entering your password! | ||
- | [user@remotehost ~]$ cd .ssh | ||
- | [user@remotehost .ssh]$ cat my_id.pub >> authorized_keys | ||
- | [user@remotehost .ssh]$ rm my_id.pub | ||
- | </ | ||
- | |||
- | ==== Setting correct permissions ==== | ||
- | On both local and remote hosts, the permissions need to be set as follows if not already set: | ||
- | <code bash> | ||
- | [user@host ~]$ chmod 700 .ssh | ||
- | [user@host ~]$ cd .ssh | ||
- | [user@host .ssh]$ chmod 600 * | ||
- | [user@host .ssh]$ chmod go+r known_hosts | ||
- | </ | ||
- | |||
- | ==== How to: Disable SSH Password Authentication ===== | ||
- | |||
- | Disabling Password Authentication is generally as simple as setting the option '' | ||
- | |||
- | However, we've discovered that some linux distributions add another configuration file **/ | ||
- | |||
- | Therefore, the easiest way to universally disable password authentication is to create a new file that sorts lexicographically before any other files that might be created in there, such as **00-disable-password-auth.conf**: | ||
- | < | ||
- | PasswordAuthentication no | ||
- | </ | ||
- | |||
- | After setting the '' | ||
- | |||
- | * on Debian/ | ||
- | systemctl reload ssh | ||
- | </ | ||
- | * on RHEL/ | ||
- | systemctl reload sshd | ||
- | </ | ||
- | |||
- | |||
- | \\ | ||
- | \\ | ||
- | ===== Google Authenticator MFA ===== | ||
- | ==== Ubuntu ==== | ||
- | |||
- | - Install **libpam-google-authenticator**:< | ||
- | apt install libpam-google-authenticator | ||
- | </ | ||
- | - Configure SSH, edit ''/ | ||
- | #uncomment | ||
- | PasswordAuthentication yes | ||
- | #uncomment and set to yes | ||
- | KbdInteractiveAuthentication yes | ||
- | </ | ||
- | - Restart SSHD Service:< | ||
- | systemctl restart ssh | ||
- | </ | ||
- | - Add this line to ''/ | ||
- | auth required pam_google_authenticator.so nullok echo_verification_code | ||
- | </ | ||
- | * NOTE: '' | ||
- | * **WARNING** If you make changes to any pam config files, make sure you have a second terminal open as root so that you can always get in to revert the change. PAM can very easily break all authentication so that you can't get in to the system any more. Double check any changes right away. Don't let the 15 minute auto logout lock you out... | ||
- | - To enforce 2FA for other services, modify the appropriate pam config file for that service | ||
- | |||
- | === Set up google authenticator for each user account === | ||
- | Users must set up their own google authenticator: | ||
- | - Log in via SSH using password | ||
- | - Run the command:< | ||
- | - Follow prompts to get a QR code (NOTE: Have the user maximize their SSH app window so the QR code is drawn properly and doesn' | ||
- | - Scan the QR code using your Google Authenticator app on your phone | ||
- | - Enter 6 digit code or -1 to skip | ||
- | - Complete the setup by answering questions: | ||
- | - Update your "/ | ||
- | - Time-based: y | ||
- | - Disallow multiple uses of the same code (prevent man-in-the-middle attacks): y | ||
- | - Permit time skew up to 4 minutes: n | ||
- | - Enable rate-limiting: | ||
- | - **Copy your backup codes somewhere safe. You can also view your backup codes by looking in the '' | ||
- | |||
- | === Disabling Google Auth === | ||
- | * Disable google auth 2FA for a specific user account by moving/ | ||
- | |||
- | |||
howto/sshkey_google2fa.1747084153.txt.gz · Last modified: 2025/05/12 21:09 by justip6