Implement 2FA for SSH servers #85
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
https://ubuntu.com/tutorials/configure-ssh-2fa#2-installing-and-configuring-required-packages
Should be trivial to implement via the
libpam-google-authenticator
package. This will require another device be setup to access servers over SSH. This strongly mitigates risk of lateral movement inside the environment if an SSH key is compromised.changed the description
changed the description
Starting with the Pi to ensure least possible impact of lockout due to botched configuration.
We run:
sudo apt install libpam-google-authenticator
to install the google authenticator PAM (pluggable authentication module) library for SSH.Then configure the google authenticator module with
google-authenticator
and when prompted use the following configuration:y
y
y
n
(refers to increasing time skew window)y
We enter our TOTP secret key into our second authentication method and save our one-time backup recovery codes.
We edit our PAM SSHD config with
sudo nano /etc/pam.d/sshd
and add the lineauth sufficient pam_google_authenticator.so nullok
at the top of the file.Then edit the SSH daemon config via
sudo nano /etc/ssh/sshd_config
and ensure the following configuration assertions exist:PubkeyAuthentication yes
AuthenticationMethods publickey,keyboard-interactive
PasswordAuthentication no
ChallengeResponseAuthentication yes
UsePAM yes
Then restart the SSH daemon with
sudo systemctl restart sshd.service
.We open a new connection to our newly-protected host
ssh -i ~/.ssh/main_id_rsa pi@pihole1
. If everything worked properly, we should see a prompt forVerification code:
.Note: If using
Tabby
as the SSH client, you may need to switch from the "Key" authentication method to the "Auto" authentication method. Otherwise you will encounter anAll configured authentication methods failed
error.marked the checklist item pi as completed
marked the checklist item jafner.chat as completed
marked the checklist item server as completed
marked the checklist item wyse as completed
VyOS is going to be a slightly different process.
https://docs.vyos.io/en/latest/configuration/system/login.html
Looks like we're going to have to update our VyOS version. OTP functionality was implemented late 2022.
This has been done to the extent of current feasibility.
Will need to revisit when VyOS issue progresses and an opportunity for an extended service window presents itself.
Consider looking at keycloak PAM:
https://www.reddit.com/r/selfhosted/comments/12omoyn/linux_system_authentication_with_keycloak_sso/
marked the checklist item nas (already has 2fa for webui) as completed
marked the checklist item backup nas (already has 2fa for webui) as completed
marked the checklist item nas (already has 2fa for webui) as incomplete
marked the checklist item backup nas (already has 2fa for webui) as incomplete
Instructions for SSH 2FA in TrueNAS: https://www.truenas.com/community/threads/2fa-ssh-with-key-auth.104282/
mentioned in issue #92
Implemented per the instructions.
2nd factor is not being requested when connecting via SSH.
Considering this done as far as can be for now.