ServerHandbook live check: run log ------------------------------------------------------------------------------ Check scripts/live/checks/ssh-permission-denied-publickey.mjs (sha256 95559155161e2f51c5785489518d65f64cbf0065ddf108bca47a0e072342e754) Ran at 2026-11-19T17:07:36Z (45 s) Result PASS, all 38 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 openssh-client 1:9.6p1-3ubuntu13.20 Setup A fresh Ubuntu 24.04 server (a VM from Ubuntu’s cloud image) with OpenSSH from Ubuntu’s archive and password login off (the cloud image’s default). The account webadmin has the key ~/.ssh/web_key; the client is the sudo user deploy on the same server (ssh to localhost), so the client’s and the server’s messages come from one run. 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 ------------------------------------------------------------------------------ What the steps changed on the server (recorded before the first step and after the last) Packages added (0) Packages upgraded (0) Packages removed (0) Services enabled at boot (0) Services disabled (0) Listening sockets opened (0) Listening sockets closed (0) Files added in /etc (0) Files changed in /etc (0) Files removed from /etc (0) Disk used on / (includes logs written during the run): +0.1 MB ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Claims (38), each with what the run saw ------------------------------------------------------------------------------ 1. ok a bare Ubuntu 24.04 server box (web-server) starts 2. ok (setup) webadmin logs in with ~/.ssh/web_key | webadmin 3. ok (setup) webadmin’s home is 750 (Ubuntu’s HOME_MODE) | 750 4. ok sshd -T: pubkeyauthentication yes, passwordauthentication no, strictmodes yes, authorizedkeysfile .ssh/authorized_keys … | pubkeyauthentication yes | passwordauthentication no | strictmodes yes | authorizedkeysfile .ssh/authorized_keys .ssh/authorized_keys2 5. ok a user that does not exist: "admin@localhost: Permission denied (publickey)." | admin@localhost: Permission denied (publickey). 6. ok the journal: Invalid user admin from … | Invalid user admin from ::1 port 40290 7. ok without -i: Permission denied (publickey) | webadmin@localhost: Permission denied (publickey). 8. ok ssh -v: only the default key names (id_rsa, id_ed25519 …) are tried, web_key is never offered | debug1: Authentications that can continue: publickey | debug1: Will attempt key: /home/deploy/.ssh/id_rsa | debug1: Will attempt key: /home/deploy/.ssh/id_ecdsa | debug1: Will attempt key: /home/deploy/.ssh/id_ecdsa_sk | debug1: Will attempt key: /home/deploy/.ssh/id_ed25519 | debug1: Will attempt key: /home/deploy/.ssh/id_ed25519_sk | debug1: Will attempt key: /home/deploy/.ssh/id_xmss | debug1: Will attempt key: /home/deploy/.ssh/id_dsa 9. ok with -i ~/.ssh/web_key: whoami prints webadmin | webadmin 10. ok ~/.ssh/config is written 11. ok ssh web: the Host entry picks the user and the key | webadmin 12. ok ssh -v: "Offering public key: …/old_key", then "Authentications that can continue: publickey", then denied | debug1: Authentications that can continue: publickey | debug1: Offering public key: /home/deploy/.ssh/old_key ED25519 SHA256:w3Aqj8CCrrMeEe77oq4A2NG2iAN62f0DH6UTyAaD6lk explicit | debug1: Authentications that can continue: publickey | webadmin@localhost: Permission denied (publickey). 13. ok the journal: Connection closed by authenticating user webadmin … [preauth] | pam_unix(sshd:session): session closed for user webadmin | Connection closed by authenticating user webadmin ::1 port 44270 [preauth] 14. ok the two fingerprints differ: the server does not know old_key | 256 SHA256:w3Aqj8CCrrMeEe77oq4A2NG2iAN62f0DH6UTyAaD6lk deploy@web-server (ED25519) | 256 SHA256:Iop83wVoJ7K0CZGxT6j8AOE2CJ30ALU9nt3FMW26WQY deploy@web-server (ED25519) 15. ok tee -a appends the public key and prints it | ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHaO8BRu1lr+ZPf5McZMUxzcGBvKughNDyw0RSUPydmr deploy@web-server 16. ok old_key now logs in | webadmin 17. ok chmod 775 the home folder 18. ok 775 (group webadmin, the user’s private group): the login still works | webadmin 19. ok chmod 777 the home folder 20. ok a world-writable home: Permission denied (publickey) | webadmin@localhost: Permission denied (publickey). 21. ok the journal: Authentication refused: bad ownership or modes for directory /home/webadmin | Authentication refused: bad ownership or modes for directory /home/webadmin | Connection closed by authenticating user webadmin ::1 port 44300 [preauth] 22. ok ls -ld: drwxrwxrwx on the home folder | drwxrwxrwx 4 webadmin webadmin 4096 Nov 19 17:07 /home/webadmin | drwx------ 2 webadmin webadmin 4096 Nov 19 17:07 /home/webadmin/.ssh | -rw------- 1 webadmin webadmin 198 Nov 19 17:08 /home/webadmin/.ssh/authorized_keys 23. ok chmod 750 the home folder 24. ok an authorized_keys anyone may write (666): Permission denied (publickey) | webadmin@localhost: Permission denied (publickey). 25. ok the journal: Authentication refused: bad ownership or modes for file /home/webadmin/.ssh/authorized_keys | Authentication refused: bad ownership or modes for file /home/webadmin/.ssh/authorized_keys | Connection closed by authenticating user webadmin ::1 port 44308 [preauth] 26. ok chmod 700 .ssh, 600 authorized_keys 27. ok ssh web: webadmin | webadmin 28. ok the client: WARNING: UNPROTECTED PRIVATE KEY FILE! … Permissions 0644 … are too open … This private key will be ignored … Permission denied (publickey) | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ | @ WARNING: UNPROTECTED PRIVATE KEY FILE! @ | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ | Permissions 0644 for '/home/deploy/.ssh/web_key' are too open. | It is required that your private key files are NOT accessible by others. | This private key will be ignored. | Load key "/home/deploy/.ssh/web_key": bad permissions | webadmin@localhost: Permission denied (publickey). 29. ok chmod 600 the private key 30. ok ssh web: webadmin | webadmin 31. ok AllowUsers without webadmin: Permission denied (publickey) | webadmin@localhost: Permission denied (publickey). 32. ok the journal: User webadmin from … not allowed because not listed in AllowUsers | User webadmin from ::1 not allowed because not listed in AllowUsers | Connection closed by invalid user webadmin ::1 port 35806 [preauth] 33. ok grep finds the line in /etc/ssh/sshd_config.d/50-allow.conf | /etc/ssh/sshd_config.d/50-allow.conf:1:AllowUsers deploy root 34. ok sed adds webadmin to the line 35. ok sshd -t prints nothing (the config is valid), and ssh reloads 36. ok ssh web: webadmin | webadmin 37. ok (webadmin logs in with its key at the end of the steps) | webadmin 38. 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 openssh-client 1:9.6p1-3ubuntu13.20 | PKG openssh-server 1:9.6p1-3ubuntu13.20 ------------------------------------------------------------------------------ Commands and what they printed (34) ------------------------------------------------------------------------------ $ sudo sshd -T | grep -E '^(pubkeyauthentication|passwordauthentication|strictmodes|authorizedkeysfile) ' pubkeyauthentication yes passwordauthentication no strictmodes yes authorizedkeysfile .ssh/authorized_keys .ssh/authorized_keys2 $ ssh -i ~/.ssh/web_key admin@localhost admin@localhost: Permission denied (publickey). $ sudo journalctl -u ssh -n 50 --no-pager -o cat | grep 'Invalid user' | tail -n 2 Invalid user admin from ::1 port 40290 $ ssh webadmin@localhost webadmin@localhost: Permission denied (publickey). $ ssh -v webadmin@localhost 2>&1 | grep -E 'Will attempt key|Offering public key|Authentications that can continue' debug1: Authentications that can continue: publickey debug1: Will attempt key: /home/deploy/.ssh/id_rsa debug1: Will attempt key: /home/deploy/.ssh/id_ecdsa debug1: Will attempt key: /home/deploy/.ssh/id_ecdsa_sk debug1: Will attempt key: /home/deploy/.ssh/id_ed25519 debug1: Will attempt key: /home/deploy/.ssh/id_ed25519_sk debug1: Will attempt key: /home/deploy/.ssh/id_xmss debug1: Will attempt key: /home/deploy/.ssh/id_dsa $ ssh -i ~/.ssh/web_key webadmin@localhost whoami webadmin $ tee ~/.ssh/config > /dev/null <<'EOF' $ Host web $ HostName localhost $ User webadmin $ IdentityFile ~/.ssh/web_key $ IdentitiesOnly yes $ EOF $ ssh web whoami webadmin $ ssh -v -i ~/.ssh/old_key webadmin@localhost 2>&1 | grep -E 'Offering public key|Authentications that can continue|Permission denied' debug1: Authentications that can continue: publickey debug1: Offering public key: /home/deploy/.ssh/old_key ED25519 SHA256:w3Aqj8CCrrMeEe77oq4A2NG2iAN62f0DH6UTyAaD6lk explicit debug1: Authentications that can continue: publickey webadmin@localhost: Permission denied (publickey). $ sudo journalctl -u ssh -n 50 --no-pager -o cat | grep webadmin | tail -n 2 pam_unix(sshd:session): session closed for user webadmin Connection closed by authenticating user webadmin ::1 port 44270 [preauth] $ ssh-keygen -lf ~/.ssh/old_key.pub 256 SHA256:w3Aqj8CCrrMeEe77oq4A2NG2iAN62f0DH6UTyAaD6lk deploy@web-server (ED25519) $ sudo ssh-keygen -lf /home/webadmin/.ssh/authorized_keys 256 SHA256:Iop83wVoJ7K0CZGxT6j8AOE2CJ30ALU9nt3FMW26WQY deploy@web-server (ED25519) $ cat ~/.ssh/old_key.pub | sudo tee -a /home/webadmin/.ssh/authorized_keys ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHaO8BRu1lr+ZPf5McZMUxzcGBvKughNDyw0RSUPydmr deploy@web-server $ ssh -i ~/.ssh/old_key webadmin@localhost whoami webadmin $ sudo chmod 775 /home/webadmin $ ssh web whoami webadmin $ sudo chmod 777 /home/webadmin $ ssh web whoami webadmin@localhost: Permission denied (publickey). $ sudo journalctl -u ssh -n 50 --no-pager -o cat | grep webadmin | tail -n 2 Authentication refused: bad ownership or modes for directory /home/webadmin Connection closed by authenticating user webadmin ::1 port 44300 [preauth] $ sudo ls -ld /home/webadmin /home/webadmin/.ssh /home/webadmin/.ssh/authorized_keys drwxrwxrwx 4 webadmin webadmin 4096 Nov 19 17:07 /home/webadmin drwx------ 2 webadmin webadmin 4096 Nov 19 17:07 /home/webadmin/.ssh -rw------- 1 webadmin webadmin 198 Nov 19 17:08 /home/webadmin/.ssh/authorized_keys $ sudo chmod 750 /home/webadmin $ ssh web whoami webadmin@localhost: Permission denied (publickey). $ sudo journalctl -u ssh -n 50 --no-pager -o cat | grep webadmin | tail -n 2 Authentication refused: bad ownership or modes for file /home/webadmin/.ssh/authorized_keys Connection closed by authenticating user webadmin ::1 port 44308 [preauth] $ sudo chmod 700 /home/webadmin/.ssh && sudo chmod 600 /home/webadmin/.ssh/authorized_keys $ ssh web whoami webadmin $ ssh web whoami @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ WARNING: UNPROTECTED PRIVATE KEY FILE! @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Permissions 0644 for '/home/deploy/.ssh/web_key' are too open. It is required that your private key files are NOT accessible by others. This private key will be ignored. Load key "/home/deploy/.ssh/web_key": bad permissions webadmin@localhost: Permission denied (publickey). $ chmod 600 ~/.ssh/web_key $ ssh web whoami webadmin $ ssh web whoami webadmin@localhost: Permission denied (publickey). $ sudo journalctl -u ssh -n 50 --no-pager -o cat | grep webadmin | tail -n 2 User webadmin from ::1 not allowed because not listed in AllowUsers Connection closed by invalid user webadmin ::1 port 35806 [preauth] $ sudo grep -Rn AllowUsers /etc/ssh/ /etc/ssh/sshd_config.d/50-allow.conf:1:AllowUsers deploy root $ sudo sed -i 's/^AllowUsers .*/& webadmin/' /etc/ssh/sshd_config.d/50-allow.conf $ sudo sshd -t && sudo systemctl reload ssh $ ssh web whoami webadmin ------------------------------------------------------------------------------ The check's source (scripts/live/checks/ssh-permission-denied-publickey.mjs) As it ran. ------------------------------------------------------------------------------ /** * KB fix: SSH "Permission denied (publickey)". Break → see → fix → prove (plan04 §1), each cause seen from BOTH ends: * what the client prints and the line sshd writes to the journal. * 1. wrong user name Invalid user admin from … * 2. the key is never offered (its own name) ssh -v: no "Offering public key" for it; fix -i or ~/.ssh/config * 3. the key is not in authorized_keys Offering … then "Authentications that can continue"; fingerprints differ * 4. home or authorized_keys group-writable Authentication refused: bad ownership or modes for directory/file … * 5. private key readable by others WARNING: UNPROTECTED PRIVATE KEY FILE! … This private key will be ignored. * 6. AllowUsers in sshd_config.d User webadmin from … not allowed because not listed in AllowUsers * * The client is the test server itself (ssh to localhost as the sudo user deploy), the account is `webadmin` with * the key ~/.ssh/web_key: the same messages a reader's own computer prints. Runs on the local VM. */ import { bareBox, reportBox } from '../lib.mjs' const RELEASE = process.env.LIVE_BOX_RELEASE || '24.04' const tee = (path, body) => `sudo tee ${path} > /dev/null <<'EOF'\n${body}\nEOF` /** a file the reader writes as themselves (no sudo) */ const teeUser = (path, body) => `tee ${path} > /dev/null <<'EOF'\n${body}\nEOF` const DENIED = /webadmin@localhost: Permission denied \(publickey\)\./ const T = 60000 const check = (ctx) => bareBox(ctx, async ({ sudoUser }) => { const { run, L } = sudoUser() /** sshd's lines about one login, after a moment for the journal (the runner's own logins are left out) */ const journal = (pattern, id) => { L('sleep 1') return run(`sudo journalctl -u ssh -n 50 --no-pager -o cat | grep ${pattern} | tail -n 2`, { id }) } // ── hidden: an account with a key, as a reader has it ────────────────────────────────── L('sudo useradd -m -s /bin/bash webadmin') L("ssh-keygen -q -t ed25519 -N '' -f ~/.ssh/web_key && ssh-keygen -q -t ed25519 -N '' -f ~/.ssh/old_key") L('sudo install -d -m 700 -o webadmin -g webadmin /home/webadmin/.ssh && sudo install -m 600 -o webadmin -g webadmin ~/.ssh/web_key.pub /home/webadmin/.ssh/authorized_keys') L('ssh-keyscan -t ed25519 localhost 2>/dev/null >> ~/.ssh/known_hosts') const base = L('ssh -o BatchMode=yes -i ~/.ssh/web_key webadmin@localhost whoami', T) ctx.check('(setup) webadmin logs in with ~/.ssh/web_key', /^webadmin$/m.test(base), base) const home = L('stat -c %a /home/webadmin') ctx.check('(setup) webadmin’s home is 750 (Ubuntu’s HOME_MODE)', home === '750', home) // ── what the server allows ────────────────────────────────────────────────────────────── const t = run("sudo sshd -T | grep -E '^(pubkeyauthentication|passwordauthentication|strictmodes|authorizedkeysfile) '", { id: 'sshd-t' }) ctx.check('sshd -T: pubkeyauthentication yes, passwordauthentication no, strictmodes yes, authorizedkeysfile .ssh/authorized_keys …', /^pubkeyauthentication yes$/m.test(t.out) && /^passwordauthentication no$/m.test(t.out) && /^strictmodes yes$/m.test(t.out) && /^authorizedkeysfile \.ssh\/authorized_keys/m.test(t.out), t.out) // ── 1. wrong user name ────────────────────────────────────────────────────────────────── const u1 = run('ssh -i ~/.ssh/web_key admin@localhost', { id: 'user-ssh', timeout: T }) ctx.check('a user that does not exist: "admin@localhost: Permission denied (publickey)."', /admin@localhost: Permission denied \(publickey\)\./.test(u1.out) && u1.exit === 255, u1.out) const u2 = journal("'Invalid user'", 'user-log') ctx.check('the journal: Invalid user admin from …', /Invalid user admin from (::1|127\.0\.0\.1)/.test(u2.out), u2.out) // ── 2. the key is never offered ───────────────────────────────────────────────────────── const o1 = run('ssh webadmin@localhost', { id: 'offer-ssh', timeout: T }) ctx.check('without -i: Permission denied (publickey)', DENIED.test(o1.out), o1.out) const o2 = run("ssh -v webadmin@localhost 2>&1 | grep -E 'Will attempt key|Offering public key|Authentications that can continue'", { id: 'offer-v', timeout: T }) ctx.check('ssh -v: only the default key names (id_rsa, id_ed25519 …) are tried, web_key is never offered', /Will attempt key: \/home\/deploy\/\.ssh\/id_ed25519/.test(o2.out) && !/web_key/.test(o2.out) && !/Offering public key/.test(o2.out), o2.out) const o3 = run('ssh -i ~/.ssh/web_key webadmin@localhost whoami', { id: 'offer-i', timeout: T }) ctx.check('with -i ~/.ssh/web_key: whoami prints webadmin', /^webadmin$/m.test(o3.out), o3.out) const cfg = run(teeUser('~/.ssh/config', 'Host web\n HostName localhost\n User webadmin\n IdentityFile ~/.ssh/web_key\n IdentitiesOnly yes'), { id: 'offer-config' }) ctx.check('~/.ssh/config is written', cfg.exit === 0, cfg.out) const o4 = run('ssh web whoami', { id: 'offer-web', timeout: T }) ctx.check('ssh web: the Host entry picks the user and the key', /^webadmin$/m.test(o4.out), o4.out) // ── 3. the key is not in authorized_keys ──────────────────────────────────────────────── const k1 = run("ssh -v -i ~/.ssh/old_key webadmin@localhost 2>&1 | grep -E 'Offering public key|Authentications that can continue|Permission denied'", { id: 'key-v', timeout: T }) ctx.check('ssh -v: "Offering public key: …/old_key", then "Authentications that can continue: publickey", then denied', /Offering public key: \/home\/deploy\/\.ssh\/old_key ED25519 SHA256:/.test(k1.out) && /Authentications that can continue: publickey/.test(k1.out.split('Offering public key')[1] ?? '') && /Permission denied \(publickey\)/.test(k1.out), k1.out) const k2 = journal('webadmin', 'key-log') ctx.check('the journal: Connection closed by authenticating user webadmin … [preauth]', /Connection closed by authenticating user webadmin .*\[preauth\]/.test(k2.out), k2.out) const k3 = run('ssh-keygen -lf ~/.ssh/old_key.pub', { id: 'key-fp-local' }) const k4 = run('sudo ssh-keygen -lf /home/webadmin/.ssh/authorized_keys', { id: 'key-fp-server' }) const fp = (s) => (s.match(/SHA256:\S+/) ?? [''])[0] ctx.check('the two fingerprints differ: the server does not know old_key', fp(k3.out) && fp(k4.out) && fp(k3.out) !== fp(k4.out), `${k3.out}\n${k4.out}`) const k5 = run('cat ~/.ssh/old_key.pub | sudo tee -a /home/webadmin/.ssh/authorized_keys', { id: 'key-add' }) ctx.check('tee -a appends the public key and prints it', /^ssh-ed25519 \S+ deploy@/.test(k5.out), k5.out) const k6 = run('ssh -i ~/.ssh/old_key webadmin@localhost whoami', { id: 'key-ok', timeout: T }) ctx.check('old_key now logs in', /^webadmin$/m.test(k6.out), k6.out) // ── 4. home folder or authorized_keys writable by others ──────────────────────────────── // Debian/Ubuntu's sshd lets a home be group-writable when the group is the user's own private group // (debian/patches/user-group-modes.patch): 775 still logs in, 777 does not const g1 = run('sudo chmod 775 /home/webadmin', { id: 'perm-775' }) ctx.check('chmod 775 the home folder', g1.exit === 0, g1.out) const g2 = run('ssh web whoami', { id: 'perm-775-ssh', timeout: T }) ctx.check('775 (group webadmin, the user’s private group): the login still works', /^webadmin$/m.test(g2.out), g2.out) const g3 = run('sudo chmod 777 /home/webadmin', { id: 'perm-777' }) ctx.check('chmod 777 the home folder', g3.exit === 0, g3.out) const p1 = run('ssh web whoami', { id: 'perm-ssh', timeout: T }) ctx.check('a world-writable home: Permission denied (publickey)', DENIED.test(p1.out), p1.out) const p2 = journal('webadmin', 'perm-log') ctx.check('the journal: Authentication refused: bad ownership or modes for directory /home/webadmin', /Authentication refused: bad ownership or modes for directory \/home\/webadmin$/m.test(p2.out), p2.out) const p3 = run('sudo ls -ld /home/webadmin /home/webadmin/.ssh /home/webadmin/.ssh/authorized_keys', { id: 'perm-ls' }) ctx.check('ls -ld: drwxrwxrwx on the home folder', /^drwxrwxrwx\s.*\/home\/webadmin$/m.test(p3.out), p3.out) const p4 = run('sudo chmod 750 /home/webadmin', { id: 'perm-fix-home' }) ctx.check('chmod 750 the home folder', p4.exit === 0, p4.out) L('sudo chmod 666 /home/webadmin/.ssh/authorized_keys') const p5 = run('ssh web whoami', { id: 'perm-ssh-2', timeout: T }) ctx.check('an authorized_keys anyone may write (666): Permission denied (publickey)', DENIED.test(p5.out), p5.out) const p6 = journal('webadmin', 'perm-log-2') ctx.check('the journal: Authentication refused: bad ownership or modes for file /home/webadmin/.ssh/authorized_keys', /bad ownership or modes for file \/home\/webadmin\/\.ssh\/authorized_keys/.test(p6.out), p6.out) const p7 = run('sudo chmod 700 /home/webadmin/.ssh && sudo chmod 600 /home/webadmin/.ssh/authorized_keys', { id: 'perm-fix' }) ctx.check('chmod 700 .ssh, 600 authorized_keys', p7.exit === 0, p7.out) const p8 = run('ssh web whoami', { id: 'perm-ok', timeout: T }) ctx.check('ssh web: webadmin', /^webadmin$/m.test(p8.out), p8.out) // ── 5. the private key is readable by others (client side) ────────────────────────────── L('chmod 644 ~/.ssh/web_key') const c1 = run('ssh web whoami', { id: 'client-ssh', timeout: T }) ctx.check('the client: WARNING: UNPROTECTED PRIVATE KEY FILE! … Permissions 0644 … are too open … This private key will be ignored … Permission denied (publickey)', /WARNING: UNPROTECTED PRIVATE KEY FILE!/.test(c1.out) && /Permissions 0644 for '\/home\/deploy\/\.ssh\/web_key' are too open\./.test(c1.out) && /This private key will be ignored\./.test(c1.out) && DENIED.test(c1.out), c1.out) const c2 = run('chmod 600 ~/.ssh/web_key', { id: 'client-fix' }) ctx.check('chmod 600 the private key', c2.exit === 0, c2.out) const c3 = run('ssh web whoami', { id: 'client-ok', timeout: T }) ctx.check('ssh web: webadmin', /^webadmin$/m.test(c3.out), c3.out) // ── 6. AllowUsers ─────────────────────────────────────────────────────────────────────── // the runner's own logins are deploy (and root for its probes): root is allowed too while this section runs L(tee('/etc/ssh/sshd_config.d/50-allow.conf', 'AllowUsers deploy root')) L('sudo systemctl reload ssh') const a1 = run('ssh web whoami', { id: 'allow-ssh', timeout: T }) ctx.check('AllowUsers without webadmin: Permission denied (publickey)', DENIED.test(a1.out), a1.out) const a2 = journal('webadmin', 'allow-log') ctx.check('the journal: User webadmin from … not allowed because not listed in AllowUsers', /User webadmin from (::1|127\.0\.0\.1) not allowed because not listed in AllowUsers/.test(a2.out), a2.out) const a3 = run('sudo grep -Rn AllowUsers /etc/ssh/', { id: 'allow-grep' }) ctx.check('grep finds the line in /etc/ssh/sshd_config.d/50-allow.conf', /\/etc\/ssh\/sshd_config\.d\/50-allow\.conf:1:AllowUsers deploy root/.test(a3.out), a3.out) const a4 = run("sudo sed -i 's/^AllowUsers .*/& webadmin/' /etc/ssh/sshd_config.d/50-allow.conf", { id: 'allow-sed' }) ctx.check('sed adds webadmin to the line', a4.exit === 0 && /AllowUsers deploy root webadmin/.test(L('cat /etc/ssh/sshd_config.d/50-allow.conf')), a4.out) const a5 = run('sudo sshd -t && sudo systemctl reload ssh', { id: 'allow-reload' }) ctx.check('sshd -t prints nothing (the config is valid), and ssh reloads', a5.exit === 0 && a5.out === '', a5.out) const a6 = run('ssh web whoami', { id: 'allow-ok', timeout: T }) ctx.check('ssh web: webadmin', /^webadmin$/m.test(a6.out), a6.out) L('sudo rm /etc/ssh/sshd_config.d/50-allow.conf && sudo systemctl reload ssh') // ── end state ─────────────────────────────────────────────────────────────────────────── const e1 = L('ssh -o BatchMode=yes web whoami', T) ctx.check('(webadmin logs in with its key at the end of the steps)', /^webadmin$/m.test(e1), e1) ctx.stepsDone() reportBox( ctx, L, `A fresh Ubuntu ${RELEASE} server (${process.env.LIVE_VPS ? 'a rented cloud server, rebuilt to the provider’s stock image' : 'a VM from Ubuntu’s cloud image'}) with OpenSSH from Ubuntu’s archive and password login off (the cloud image’s default). The account webadmin has the key ~/.ssh/web_key; the client is the sudo user deploy on the same server (ssh to localhost), so the client’s and the server’s messages come from one run.`, ['openssh-server', 'openssh-client'], ) }) export default check