Skip to content
atori.tech

3.4 Login with SSH keys

Difficulty: Easy Tested v0.18.5.4

SSH keys are much stronger than passwords and can't be brute-forced. With keys in place, you can turn password logins off completely.

Create a key on your regular computer

Skip this if you already have one (ls ~/.ssh/id_ed25519.pub).

ssh-keygen -t ed25519 -C "monerobox"

Give it a passphrase. Your OS keychain or ssh-agent can remember it.

Copy it to the node

ssh-copy-id nodeadmin@NODE_IP
type $env:USERPROFILE\.ssh\id_ed25519.pub | ssh nodeadmin@NODE_IP "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"

Log out, then log in again with ssh nodeadmin@NODE_IP. It should ask for your key passphrase (or nothing), not Password [A].

Turn off password logins

Danger

Only do this after you've confirmed key login works, and keep your current session open until you've tested a new one. Losing your key means you need a monitor and keyboard to get back in.

sudo nano /etc/ssh/sshd_config.d/10-monerobox.conf
PasswordAuthentication no
KbdInteractiveAuthentication no
PermitRootLogin no

Why 10-

SSH reads the files in sshd_config.d in alphabetical order, and the first value it finds for a setting wins. Ubuntu's installer writes 50-cloud-init.conf with PasswordAuthentication yes when Allow password authentication over SSH was ticked (the default). A file named 10-… is read before it, so your setting wins. A file named 99-… would be silently ignored.

sudo sshd -t && sudo systemctl reload ssh
sudo sshd -T | grep -E '^(passwordauthentication|kbdinteractiveauthentication|permitrootlogin)'
permitrootlogin no
passwordauthentication no
kbdinteractiveauthentication no

Open a new terminal and test ssh nodeadmin@NODE_IP. Then try logging in with a password from another machine. It should be refused with Permission denied (publickey).

To allow password logins again, delete the file and reload: sudo rm /etc/ssh/sshd_config.d/10-monerobox.conf && sudo systemctl reload ssh.

Password [A] is still needed for sudo.