ServerHandbook live check: run log ------------------------------------------------------------------------------ Article https://serverhandbook.com/kb/ssh-key-login-ubuntu-24-04 Check scripts/live/checks/ssh-key-login-ubuntu-24-04.mjs (sha256 1d5ce4394b96c37d25893a0423c710560120b5141c6ee585bc38e96d4b0866c7) Ran at 2026-11-11T02:25:54Z (126 s) Result PASS, all 23 claims held Tested on System Ubuntu 24.04.5 LTS Kernel 6.8.0-147-generic Package openssh-server 1:9.6p1-3ubuntu13.20 Package cloud-init 26.1-0ubuntu1~24.04.1 Setup A fresh Ubuntu 24.04 server from a provider that set a password (cloud-init turned SSH password login on), with the sudo user deploy. Your computer: Ubuntu 24.04.5 LTS, openssh-client 1:9.6p1-3ubuntu13.20. Every version above was read from the server at run time. Passwords used on the throwaway test server are shown as [password]. How we test: https://serverhandbook.com/how-we-test ------------------------------------------------------------------------------ Claims (23), each with what the run saw ------------------------------------------------------------------------------ 1. ok a bare Ubuntu 24.04 server box (web-server) starts 2. ok a fresh server from a provider that set a password has password login ON | To run a command as administrator (user "root"), use "sudo ". | See "man sudo_root" for details. | | passwordauthentication yes 3. ok 50-cloud-init.conf says yes and 60-cloudimg-settings.conf says no; sshd_config has only a commented line | /etc/ssh/sshd_config.d/60-cloudimg-settings.conf:PasswordAuthentication no | /etc/ssh/sshd_config.d/50-cloud-init.conf:PasswordAuthentication yes 4. ok sshd_config includes sshd_config.d/*.conf at line 12, before its own settings | 12:Include /etc/ssh/sshd_config.d/*.conf 5. ok SSH is socket-activated: ssh.socket and ssh.service both active | active | active 6. ok a fresh "your computer" machine (Ubuntu 24.04, openssh-client only) starts 7. ok (tested on) your computer reports its OS and OpenSSH client version | PRETTY_NAME="Ubuntu 24.04.5 LTS" | PKG openssh-client 1:9.6p1-3ubuntu13.20 8. ok ssh-keygen writes id_ed25519 and id_ed25519.pub | Generating public/private ed25519 key pair. | Enter file in which to save the key (/home/you/.ssh/id_ed25519): | Created directory '/home/you/.ssh'. | Enter passphrase (empty for no passphrase): | Enter same passphrase again: | Your identification has been saved in /home/you/.ssh/id_ed25519 | Your public key has been saved in /home/you/.ssh/id_ed25519.pub | The key fingerprint is: | SHA256:aBdwrKMeqAJdYTErzkJPTk08UAcpB6VWerH0KxSH63c you@laptop | The key's randomart image is: | +--[ED25519 256]--+ | | oO@=+. | | | .XOBo. | | | ..B+*oo. | | |.o*.+.o... | | |..o=.oooS | | |..o oo.o E | | |.. . .. . | | |o . | | |. | | +----[SHA256]-----+ 9. ok the private key is -rw------- (600) and the public key -rw-r--r-- (644) | total 8 | -rw------- 1 you you 444 Nov 11 02:26 id_ed25519 | -rw-r--r-- 1 you you 92 Nov 11 02:26 id_ed25519.pub 10. ok ssh-copy-id reports "Number of key(s) added: 1" | /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/you/.ssh/id_ed25519.pub" | The authenticity of host '203.0.113.10 (203.0.113.10)' can't be established. | ED25519 key fingerprint is SHA256:Xk2uU+nrlOEaG2hEC5JYqzBNxmW8qimJIkqr6rxBG3U. | This key is not known by any other names. | Are you sure you want to continue connecting (yes/no/[fingerprint])? yes | /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed | /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys | deploy@203.0.113.10's password: | | Number of key(s) added: 1 | | Now try logging into the machine, with: "ssh 'deploy@203.0.113.10'" | and check to make sure that only the key(s) you wanted were added. 11. ok ssh now asks for the key passphrase, then opens a shell as deploy on web-server | Enter passphrase for key '/home/you/.ssh/id_ed25519': | Welcome to Ubuntu 24.04.5 LTS (GNU/Linux 6.8.0-147-generic x86_64) | | * Documentation: https://help.ubuntu.com | * Management: https://landscape.canonical.com | * Support: https://ubuntu.com/pro | | System information as of Wed Nov 11 02:26:37 UTC 2026 | | System load: 1.97 | Usage of /: 7.0% of 23.17GB | Memory usage: 9% | Swap usage: 0% | Processes: 132 | Users logged in: 0 | IPv4 address for enp0s2: 203.0.113.10 | IPv6 address for enp0s2: 2001:db8::10 | | | Expanded Security Maintenance for Applications is not enabled. | | 0 updates can be applied immediately. | | Enable ESM Apps to receive additional future security updates. | See https://ubuntu.com/esm or run: sudo pro status | | | The list of available updates is more than a week old. | To check for new updates run: sudo apt update | New release '26.04.1 LTS' available. | Run 'do-release-upgrade' to upgrade to it. | | | Last login: Wed Nov 11 02:26:39 2026 from 203.0.113.1 | deploy@web-server:~$ exit | logout | Connection to 203.0.113.10 closed. 12. ok setting PasswordAuthentication no in sshd_config leaves it ON: 50-cloud-init.conf is read first | passwordauthentication yes 13. ok the drop-in is written | PasswordAuthentication no 14. ok sshd -t finds no error (prints nothing, exit 0) | 0 15. ok before the reload, the running sshd still accepts a password | deploy@203.0.113.10's password: 16. ok systemctl reload ssh succeeds on the socket-activated service 17. ok sshd -T now says passwordauthentication no | passwordauthentication no 18. ok a password login is refused: "Permission denied (publickey)." | deploy@203.0.113.10: Permission denied (publickey). 19. ok the key still logs in | Enter passphrase for key '/home/you/.ssh/id_ed25519': | passwordauthentication no 20. ok the server reboots | 52 21. ok after a reboot, password login is still refused | deploy@203.0.113.10: Permission denied (publickey). 22. ok undo: removing the drop-in and reloading turns password login back on | passwordauthentication yes 23. ok (tested on) the box reports its OS, kernel and the version of 2 package(s) | PRETTY_NAME="Ubuntu 24.04.5 LTS" | VIRT=none | KERNEL=6.8.0-147-generic | PKG cloud-init 26.1-0ubuntu1~24.04.1 | PKG openssh-server 1:9.6p1-3ubuntu13.20 ------------------------------------------------------------------------------ Commands and what they printed (19) ------------------------------------------------------------------------------ $ sudo sshd -T | grep -i "^passwordauthentication" To run a command as administrator (user "root"), use "sudo ". See "man sudo_root" for details. passwordauthentication yes $ sudo grep -ri "^passwordauthentication" /etc/ssh/sshd_config /etc/ssh/sshd_config.d/ /etc/ssh/sshd_config.d/60-cloudimg-settings.conf:PasswordAuthentication no /etc/ssh/sshd_config.d/50-cloud-init.conf:PasswordAuthentication yes $ grep -n "^Include" /etc/ssh/sshd_config 12:Include /etc/ssh/sshd_config.d/*.conf $ systemctl is-active ssh.socket ssh.service active active $ ssh-keygen -t ed25519 Generating public/private ed25519 key pair. Enter file in which to save the key (/home/you/.ssh/id_ed25519): Created directory '/home/you/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/you/.ssh/id_ed25519 Your public key has been saved in /home/you/.ssh/id_ed25519.pub The key fingerprint is: SHA256:aBdwrKMeqAJdYTErzkJPTk08UAcpB6VWerH0KxSH63c you@laptop The key's randomart image is: +--[ED25519 256]--+ | oO@=+. | | .XOBo. | | ..B+*oo. | |.o*.+.o... | |..o=.oooS | |..o oo.o E | |.. . .. . | |o . | |. | +----[SHA256]-----+ $ ls -l ~/.ssh/ total 8 -rw------- 1 you you 444 Nov 11 02:26 id_ed25519 -rw-r--r-- 1 you you 92 Nov 11 02:26 id_ed25519.pub $ ssh-copy-id deploy@203.0.113.10 /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/you/.ssh/id_ed25519.pub" The authenticity of host '203.0.113.10 (203.0.113.10)' can't be established. ED25519 key fingerprint is SHA256:Xk2uU+nrlOEaG2hEC5JYqzBNxmW8qimJIkqr6rxBG3U. This key is not known by any other names. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys deploy@203.0.113.10's password: Number of key(s) added: 1 Now try logging into the machine, with: "ssh 'deploy@203.0.113.10'" and check to make sure that only the key(s) you wanted were added. $ ssh deploy@203.0.113.10 Enter passphrase for key '/home/you/.ssh/id_ed25519': Welcome to Ubuntu 24.04.5 LTS (GNU/Linux 6.8.0-147-generic x86_64) * Documentation: https://help.ubuntu.com * Management: https://landscape.canonical.com * Support: https://ubuntu.com/pro System information as of Wed Nov 11 02:26:37 UTC 2026 System load: 1.97 Usage of /: 7.0% of 23.17GB Memory usage: 9% Swap usage: 0% Processes: 132 Users logged in: 0 IPv4 address for enp0s2: 203.0.113.10 IPv6 address for enp0s2: 2001:db8::10 Expanded Security Maintenance for Applications is not enabled. 0 updates can be applied immediately. Enable ESM Apps to receive additional future security updates. See https://ubuntu.com/esm or run: sudo pro status The list of available updates is more than a week old. To check for new updates run: sudo apt update New release '26.04.1 LTS' available. Run 'do-release-upgrade' to upgrade to it. Last login: Wed Nov 11 02:26:39 2026 from 203.0.113.1 deploy@web-server:~$ exit logout Connection to 203.0.113.10 closed. $ sudo sed -i 's/^#PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config && sudo systemctl reload ssh $ sudo sshd -T | grep -i "^passwordauthentication" passwordauthentication yes $ echo "PasswordAuthentication no" | sudo tee /etc/ssh/sshd_config.d/00-keys-only.conf PasswordAuthentication no $ sudo sshd -t $ (probe, not shown) password login before the reload deploy@203.0.113.10's password: $ sudo systemctl reload ssh $ sudo sshd -T | grep -i "^passwordauthentication" passwordauthentication no $ ssh -o PubkeyAuthentication=no deploy@203.0.113.10 deploy@203.0.113.10: Permission denied (publickey). $ ssh deploy@203.0.113.10 "sudo sshd -T | grep -i ^passwordauthentication" Enter passphrase for key '/home/you/.ssh/id_ed25519': passwordauthentication no $ ssh -o PubkeyAuthentication=no deploy@203.0.113.10 deploy@203.0.113.10: Permission denied (publickey). $ sudo rm /etc/ssh/sshd_config.d/00-keys-only.conf && sudo systemctl reload ssh && sudo sshd -T | grep -i "^passwordauthentication" passwordauthentication yes ------------------------------------------------------------------------------ The check's source (scripts/live/checks/ssh-key-login-ubuntu-24-04.mjs) As it ran. ------------------------------------------------------------------------------ /** * KB: Set up SSH key login on Ubuntu 24.04 and turn off password login. * * Two machines, as a reader has them: "your computer" (box/client.mjs, user `you`) makes the key and copies it; the * server (VM box, as a provider hands it over WITH a root password, so cloud-init has turned password login on) gets * password login switched off. The sudo user `deploy` has a password, as the "create a sudo user" article leaves it. * Every claim below is one the article makes. */ import { asRoot, rebootBox } from '../box.mjs' import { bareBox, reportBox, withClient } from '../lib.mjs' export const meta = {} const SERVER = 'deploy@203.0.113.10' // throwaway test values for a box deleted after the run; shown as [password] in the published log const DEPLOY_PASSWORD = '[password]' const KEY_PHRASE = '[password]' const ROOT_PASSWORD = '[password]' const DROPIN = '/etc/ssh/sshd_config.d/00-keys-only.conf' const check = (ctx) => bareBox( ctx, async ({ sudoUser }) => { const { run, L } = sudoUser() const deployPw = ctx.secret(DEPLOY_PASSWORD) asRoot(`echo 'deploy:${deployPw}' | chpasswd`) const phrase = ctx.secret(KEY_PHRASE) // ── the starting point the article describes ───────────────────────────────────────────── const before = run('sudo sshd -T | grep -i "^passwordauthentication"', { id: 'pw-before' }) ctx.check('a fresh server from a provider that set a password has password login ON', /^passwordauthentication yes$/m.test(before.out), before.out) const who = run('sudo grep -ri "^passwordauthentication" /etc/ssh/sshd_config /etc/ssh/sshd_config.d/', { id: 'which-file' }) ctx.check( '50-cloud-init.conf says yes and 60-cloudimg-settings.conf says no; sshd_config has only a commented line', /50-cloud-init\.conf:PasswordAuthentication yes/.test(who.out) && /60-cloudimg-settings\.conf:PasswordAuthentication no/.test(who.out) && !/sshd_config:PasswordAuthentication/.test(who.out), who.out, ) const inc = run('grep -n "^Include" /etc/ssh/sshd_config') ctx.check('sshd_config includes sshd_config.d/*.conf at line 12, before its own settings', /^12:Include \/etc\/ssh\/sshd_config\.d\/\*\.conf$/m.test(inc.out), inc.out) const sock = run('systemctl is-active ssh.socket ssh.service', { id: 'socket' }) ctx.check('SSH is socket-activated: ssh.socket and ssh.service both active', sock.out.split('\n').filter((l) => l.trim() === 'active').length === 2, sock.out) await withClient(ctx, async (pc) => { // ── step 1: make a key on your computer ─────────────────────────────────────────────── const kg = pc.ask( 'ssh-keygen -t ed25519', [ ['Enter file in which to save the key', ''], ['Enter passphrase', phrase], ['Enter same passphrase again', phrase], ], ) ctx.check('ssh-keygen writes id_ed25519 and id_ed25519.pub', kg.exit === 0 && /id_ed25519\.pub/.test(kg.out), kg.out) const perms = pc.run('ls -l ~/.ssh/') ctx.check('the private key is -rw------- (600) and the public key -rw-r--r-- (644)', /-rw------- .* id_ed25519\n/.test(perms.out + '\n') && /-rw-r--r-- .* id_ed25519\.pub/.test(perms.out), perms.out) // ── step 2: copy the public key to the server ───────────────────────────────────────── const cp = pc.ask(`ssh-copy-id ${SERVER}`, [ ['continue connecting', 'yes'], ['password:', deployPw], ]) ctx.check('ssh-copy-id reports "Number of key(s) added: 1"', /Number of key\(s\) added: 1/.test(cp.out), cp.out) // ── step 3: log in with the key (asks for the KEY's passphrase, not the server password) ── const li = pc.ask(`ssh ${SERVER}`, [ ['Enter passphrase for key', phrase], ['deploy@web-server:~\\$', 'exit'], ]) ctx.check('ssh now asks for the key passphrase, then opens a shell as deploy on web-server', /Enter passphrase for key/.test(li.out) && /deploy@web-server/.test(li.out) && !/deploy@203\.0\.113\.10's password/.test(li.out), li.out) // ── why editing sshd_config (what most guides say) does nothing here ───────────────── L(`sudo cp /etc/ssh/sshd_config /root/sshd_config.orig`) run(`sudo sed -i 's/^#PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config && sudo systemctl reload ssh`, { id: 'wrong-edit' }) const wrong = run('sudo sshd -T | grep -i "^passwordauthentication"', { id: 'pw-after-wrong-edit' }) ctx.check('setting PasswordAuthentication no in sshd_config leaves it ON: 50-cloud-init.conf is read first', /^passwordauthentication yes$/m.test(wrong.out), wrong.out) L('sudo cp /root/sshd_config.orig /etc/ssh/sshd_config && sudo rm /root/sshd_config.orig && sudo systemctl reload ssh') // ── step 4: a drop-in that sorts first ──────────────────────────────────────────────── const w = run(`echo "PasswordAuthentication no" | sudo tee ${DROPIN}`) ctx.check('the drop-in is written', w.exit === 0 && /PasswordAuthentication no/.test(w.out), w.out) const t = run('sudo sshd -t') ctx.check('sshd -t finds no error (prints nothing, exit 0)', t.exit === 0 && t.out === '', `${t.exit} ${t.out}`) const pre = pc.ask(`ssh -o PubkeyAuthentication=no ${SERVER} true`, [['password:', deployPw]], { show: '(probe, not shown) password login before the reload' }) ctx.check('before the reload, the running sshd still accepts a password', pre.exit === 0, pre.out) const rl = run('sudo systemctl reload ssh') ctx.check('systemctl reload ssh succeeds on the socket-activated service', rl.exit === 0, rl.out) const after = run('sudo sshd -T | grep -i "^passwordauthentication"', { id: 'pw-after' }) ctx.check('sshd -T now says passwordauthentication no', /^passwordauthentication no$/m.test(after.out), after.out) // ── step 5: prove it, from a NEW session ───────────────────────────────────────────── const pw = pc.run(`ssh -o PubkeyAuthentication=no ${SERVER}`, { id: 'denied' }) ctx.check('a password login is refused: "Permission denied (publickey)."', pw.exit === 255 && /Permission denied \(publickey\)/.test(pw.out), pw.out) const ok = pc.ask(`ssh ${SERVER} "sudo sshd -T | grep -i ^passwordauthentication"`, [['Enter passphrase for key', phrase]], { id: 'key-still-works' }) ctx.check('the key still logs in', ok.exit === 0 && /passwordauthentication no/.test(ok.out), ok.out) // ── it survives a reboot (cloud-init does not rewrite it) ───────────────────────────── const secs = rebootBox() ctx.check('the server reboots', typeof secs === 'number', String(secs)) const pw2 = pc.run(`ssh -o PubkeyAuthentication=no ${SERVER}`, { id: 'denied-after-reboot' }) ctx.check('after a reboot, password login is still refused', pw2.exit === 255 && /Permission denied \(publickey\)/.test(pw2.out), pw2.out) // ── undo ────────────────────────────────────────────────────────────────────────────── const u = run(`sudo rm ${DROPIN} && sudo systemctl reload ssh && sudo sshd -T | grep -i "^passwordauthentication"`, { id: 'undo' }) ctx.check('undo: removing the drop-in and reloading turns password login back on', /^passwordauthentication yes$/m.test(u.out), u.out) reportBox(ctx, L, `A fresh Ubuntu 24.04 server from a provider that set a password (cloud-init turned SSH password login on), with the sudo user deploy. Your computer: ${pc.os}, openssh-client ${pc.openssh}.`, ['openssh-server', 'cloud-init']) }) }, { rootPassword: ROOT_PASSWORD }, ) export default check