ShellProven
Lesson 08 · tested on Debian 13

SSH keys from scratch: generate, install, shortcut with ~/.ssh/config, turn off passwords

Set up SSH key login from zero: generate an ed25519 key, see what ssh-copy-id actually does on the server, find out why a chmod 777 home folder silently breaks key login, create a short alias in ~/.ssh/config, and safely switch off password logins on the server (and check that it worked).

Video coming soon — @ShellProven

Commands

Exactly as run in the video. Full folder with setup script and log: terminal-tutorials/ssh-keys.

# 1. Generate a key
$ ssh-keygen -t ed25519 -C "laptop" -f ~/.ssh/id_ed25519 -N ""
Generating public/private ed25519 key pair.
Your identification has been saved in /root/.ssh/id_ed25519
Your public key has been saved in /root/.ssh/id_ed25519.pub
The key fingerprint is:
SHA256:yZJMUMO8ZslIf2trDS5G/fYiQl2u8TCJZGaxeYiAG5o laptop
The key's randomart image is:
+--[ED25519 256]--+
| .  .+o          |
|o . ..+.         |
|.+ o =.B         |
|E   oo/oo..      |
|     B+*S=       |
|      +.@ .      |
|     o o @       |
|      + * *      |
|     . + o o.    |
+----[SHA256]-----+
$ ls -l ~/.ssh
total 8
-rw------- 1 root root 399 Nov 21 19:47 id_ed25519
-rw-r--r-- 1 root root  88 Nov 21 19:47 id_ed25519.pub

# 2. Install the public key on the server
$ install -d -m 700 -o deploy -g deploy /home/deploy/.ssh && install -m 600 -o deploy -g deploy ~/.ssh/id_ed25519.pub /home/deploy/.ssh/authorized_keys
$ ssh -o StrictHostKeyChecking=accept-new deploy@localhost whoami
Warning: Permanently added 'localhost' (ED25519) to the list of known hosts.
deploy

# 3. Why key login suddenly stops working
$ chmod 777 /home/deploy && ssh -o BatchMode=yes deploy@localhost whoami
deploy@localhost: Permission denied (publickey,password).
$ chmod 700 /home/deploy && ssh -o BatchMode=yes deploy@localhost whoami
deploy

# 4. A shortcut in ~/.ssh/config
$ printf 'Host web\n    HostName localhost\n    User deploy\n    IdentityFile ~/.ssh/id_ed25519\n' > ~/.ssh/config && chmod 600 ~/.ssh/config
$ cat ~/.ssh/config
Host web
    HostName localhost
    User deploy
    IdentityFile ~/.ssh/id_ed25519
$ ssh web 'whoami; hostname'
deploy
demo

# 5. Turn off password logins
$ sshd -T | grep -i '^passwordauthentication'
passwordauthentication yes
$ echo 'PasswordAuthentication no' > /etc/ssh/sshd_config.d/10-no-passwords.conf && sshd -t && echo config OK
config OK
$ kill -HUP "$(cat /run/sshd.pid)" && sleep 1 && sshd -T | grep -i '^passwordauthentication'
passwordauthentication no
$ ssh -o PubkeyAuthentication=no -o BatchMode=yes deploy@localhost true
deploy@localhost: Permission denied (publickey).
$ ssh web 'echo key login still works'
key login still works

Quick check

Same two questions as in the video. Checked here, in your browser — nothing is sent anywhere.

Transparency. Script and narration made with AI, human-reviewed. The robot and the dog are AI-generated cartoon characters. The commands and their output are real runs in a container.