Local privilege 2FA with SSH Keys
Local Privileges Account 2FA
Local privileged accounts can have 2FA enabled, which uses an SSH key or password as the first factor and an approval push as the second factor. After the first factor succeeds, AuthNull sends a push through your organisation's MFA provider (Settings → MFA Provider: AuthNull Authenticator, Duo Security or Okta Verify). When it is approved, the user is logged in to the endpoint; when it is denied or not answered, the login is refused.
For AuthNull Authenticator, each person who logs in needs a registered phone: Users → row ⋯ → Register device.
This page covers SSH keys as the first factor. For passwords, see Configure Local 2FA with Passwords.
If the endpoint is reached through an AuthNull gateway, you do not need a PAM module on the endpoint: the gateway asks for the push and records the session. See How to Set Up a Gateway and Connect.
Configuring Local Privileged Account for Logging via SSH Keys
Generating Keys for SSH Login
-
Use the command:
ssh-keygen -
To transfer keys, use the command below:
cat ~/.ssh/id_rsa.pub | ssh username@ipaddress "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"
Configuring the AuthNull PAM Module for SSH Login
-
Install the AuthNull agent and the AuthNull PAM module on the endpoint as described in Agent based MFA for Linux (Part 1 and Part 2). The module's
configurescript updates the SSH and PAM settings. -
For SSH Key authentication, make sure the lines below are at the end of the
sshd_configfile, so that the key is required first and the push second. Path:/etc/ssh/sshd_configAuthenticationMethods publickey,keyboard-interactive
KbdInteractiveAuthentication yes -
Restart the SSH service:
sudo systemctl restart sshd -
Now log in to the VM using SSH:
ssh username@ipaddressa. Enter the passphrase for the private key (make sure the public key is placed inside the
$HOME/.ssh/authorized_keyspath).b. The second factor starts: approve the push on your phone. Check the logs from
/var/log/auth.log(for Ubuntu-based systems) or/var/log/secure(for CentOS-based systems). -
The following are issues you may encounter while building the PAM module:
a. PAM (header) not found
-
On CentOS and RHEL VMs, install the
pam-develpackage:sudo yum install pam-devel -
On Debian/Ubuntu VMs, install
libpam0g-dev:sudo apt-get install libpam0g-dev
b. Autoconf not installed/found
sudo apt-get install autoconf automake gdb git libffi-dev zlib1g-dev libssl-dev(For Debian/Ubuntu)
-
Note: To exclude a user group from AuthNull's PAM authentication, configure the following in /etc/pam.d/sshd before the AuthNull line (this will exclude users in the group {group_name} from MFA):
auth [success=done default=ignore] pam_succeed_if.so user ingroup group_name
To keep an emergency account that logs in with an SSH key only, see Break Glass Account in SSH.