How-to

Set Up Passwordless SSH from Start to Finish

Passwordless does not mean unprotected. It means logins use keys, the passphrase stays on your side, and the server stops accepting passwords at all.

What does passwordless SSH really involve?

Two separate changes. On your side, you log in with a key, and an agent remembers the unlocked key so you are not asked for a passphrase on every connection. On the server side, you turn off password logins so nobody can try guessing one. Doing only the first part is convenient but leaves the door open to brute force; doing the second part before the first works locks you out. The order below avoids both.

Step 1: Create a personal admin user

Machines from us arrive with root and a password from the panel. Daily work is safer under a named account:

useradd -m -s /bin/bash -G sudo tomas      # Ubuntu, Debian
useradd -m -G wheel tomas                  # Rocky Linux, AlmaLinux, CentOS Stream
passwd tomas                               # sudo will ask for this password

The account still gets a password, but only for sudo on the machine itself. It will not work over SSH once step 4 is done.

Step 2: How do I install the key for that user?

If you already log in as root with a key, copy it across; otherwise paste your .pub line into the new file:

install -d -o tomas -g tomas -m 0700 /home/tomas/.ssh
echo 'ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJq... tomas@desk' >> /home/tomas/.ssh/authorized_keys
chown tomas:tomas /home/tomas/.ssh/authorized_keys
chmod 600 /home/tomas/.ssh/authorized_keys

On Enterprise Linux images, finish with restorecon -Rv /home/tomas/.ssh. Creating a key is covered in Log in with an SSH key.

Step 3: How do I stop typing the passphrase?

Let an agent hold the decrypted key in memory. Most Linux desktops start one at login; on macOS, add these lines to ~/.ssh/config so the keychain stores the passphrase:

Host *
    AddKeysToAgent yes
    UseKeychain yes

On Linux, AddKeysToAgent yes alone loads the key into the running agent on first use. Windows has an OpenSSH agent service; enable it once in an administrator PowerShell with Get-Service ssh-agent | Set-Service -StartupType Automatic and Start-Service ssh-agent, then run ssh-add. From now on, the first connection asks for the passphrase and later ones do not.

Step 4: How do I switch off passwords on the server?

First, test the key login as the new user from a fresh terminal and confirm sudo -v works there. Then write a drop-in. Its name should sort early, because the first value read wins and some images ship drop-ins that enable passwords:

cat > /etc/ssh/sshd_config.d/01-nopass.conf <<'EOF'
PasswordAuthentication no            # the core switch
KbdInteractiveAuthentication no      # PAM prompts count as passwords too
PermitEmptyPasswords no
PermitRootLogin prohibit-password    # root keeps key access only
EOF
grep -rl -i 'passwordauthentication yes' /etc/ssh/sshd_config.d/ || true
sshd -t && systemctl reload ssh.service   # sshd.service on Enterprise Linux

Use systemctl reload sshd on Rocky Linux, AlmaLinux and CentOS Stream. If the grep lists a file, remove that line or rename your drop-in so it sorts first.

Step 5: How do I prove passwords are off?

Check the effective configuration, then try a password-only login from outside:

sshd -T | grep -E '^(passwordauthentication|kbdinteractiveauthentication|permitrootlogin) '
ssh -o PubkeyAuthentication=no -o PreferredAuthentications=password tomas@203.0.113.25

The second command should fail at once with Permission denied (publickey), without ever asking for a password. That is the result you want.

How does automation fit in?

Scripts cannot type passphrases, so give each job its own key without a passphrase and restrict it in authorized_keys:

OptionEffect
from="198.51.100.12"Key works only from that address
command="/usr/local/bin/pull-backup"Runs only that command
restrictNo forwarding, no terminal, no agent
expiry-time="20271231"Key stops working after that date

A leaked automation key with these options can do very little. Keep one key per job, so you can revoke one without touching the rest.

What is my recovery plan?

With passwords off, your keys are the only way in. Keep two keys in authorized_keys: your daily one and a backup stored offline. Save your public key in the panel as well. In the worst case, a reinstall from the panel with that key selected gives you a fresh, reachable system, though it erases the disks, so backups of your data remain essential.

Keep Reading

Log in with an SSH key

Create an ed25519 key, install it on your machine through the panel or ssh-copy-id, and log in without typing the root password.

Open

SSH root login settings

What each PermitRootLogin value does, how to move daily work to a sudo user and when key-only root login is reasonable.

Open

Harden SSH on Linux

A practical hardening list for sshd on a fresh dedicated box: keys, users, rate limits, firewall scope and an outside audit.

Open

SSH keys

How SSH key pairs replace passwords, how to make an ed25519 key and how to have it placed on your machine at install time.

Open

FAQ

Quick Answers

No. Keys cannot be guessed, and with passwords disabled the server rejects every brute-force attempt.

A drop-in file read earlier may set PasswordAuthentication yes. Run sshd -T to see the effective value and fix that file.

Yes. The agent keeps the unlocked key in memory, so you type the passphrase once per session.

Give each job its own unencrypted key and limit it with from, command and restrict options in authorized_keys.

Without passwords, recovery means reinstalling from the panel with a new key selected, which erases the disks.