How to setup MFA on an OpenBSD server#
In a terminal prompt while logged in as root#
- Install necessary packages
1
| pkg_add login_oath oath_toolbox vim
|
- Generate the hex code for the authenticator
1
| openssl rand -hex 20 > ~/.totp-key
|
- Set the correct permissions for the key
- View the generated hex key
- Using the key convert to base32 for your authenticator app and get the latest code to verify
1
| oathtool --verbose --totp "HEX_KEY_HERE"
|
- Modify the login.conf file to add the following
1
2
| auth-ftp-defaults:auth-ftp=passwd:
auth-ssh-defaults:auth-ssh=-totp: #ADD THIS LINE
|
Depending on what authentication class you want to modify you will need to add the following:
1
| :tc=auth-ssh-defaults:\
|
- After making the changes you will need to update the login.conf db to reflect your changes
1
| cap_mkdb /etc/login.conf
|
- Modify the sshd_config to use the totp code
1
2
3
4
5
6
7
| PermitRootLogin no
PubkeyAuthentication yes
AuthorizedKeyFiles .ssh/authorized_keys
PasswordAuthentication yes
KbdInteractiveAuthentication yes
AuthenticationMethods publickey,password
Subsystem sftp /usr/libexec/sftp-server
|
- Verify that your ssh_config file is valid
- Restart sshd to finalize the changes
Verify the changes are working#
- Attempt to login over ssh
- You should be prompted to enter your ssh key’s password and after you will be prompted to enter your password
Even though it says “password”, it is your otp code that is being requested
ex. user@server’s password: <ENTER_CODE_HERE>
- Once you enter your otp code you should be logged in