Part 2: Connect from your computer
7. SSH from a Mac#
What you'll do: control the server from your Mac's Terminal, first with a password, then with a key (safer, and no password typing). Time: 20 minutes.
What is SSH? What is a key?#
SSH opens the server's terminal inside a window on your Mac. Everything you type there runs on the server.
A key is a pair of files:
flowchart LR
subgraph Mac["Your Mac"]
PK["Private key<br/>id_ed25519_homeserver<br/>NEVER share"]
end
subgraph Server["Server"]
PUB["Public key<br/>(copy in authorized_keys)<br/>safe to share"]
end
PK -- "proves it's you" --> PUB
Think of the public key as a lock you install on the server, and the private key as the only key that opens it. The private key never leaves your Mac.
Step 1: First connection (with password)#
ssh alex@homeserver.local
The first time, you see:
The authenticity of host 'homeserver.local' can't be established.
ED25519 key fingerprint is SHA256:Xy3...
Are you sure you want to continue connecting (yes/no/[fingerprint])?
Type yes and press Enter. Then type your server password (nothing shows while you type).
The prompt changes to alex@homeserver:~$, so you're on the server. Type exit to come back to your Mac.
Step 2: Make a key (on your Mac)#
ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519_homeserver -C "mac-homeserver"
It asks for a passphrase. Choose one and save it in your password manager. The passphrase protects the key if your Mac is stolen.
This creates two files: id_ed25519_homeserver (private) and id_ed25519_homeserver.pub (public).
Step 3: Copy the public key to the server#
ssh-copy-id -i ~/.ssh/id_ed25519_homeserver.pub alex@homeserver.local
Type your server password one last time. It should say Number of key(s) added: 1.
Step 4: Create a shortcut#
So you can type ssh homeserver instead of the long command:
nano ~/.ssh/config
Paste this at the end of the file (keep anything already there):
Host homeserver
HostName homeserver.local
User alex
IdentityFile ~/.ssh/id_ed25519_homeserver
IdentitiesOnly yes
AddKeysToAgent yes
UseKeychain yes
Save with Ctrl+O Enter and exit with Ctrl+X.
Step 5: Remember the passphrase in the Mac Keychain#
ssh-add --apple-use-keychain ~/.ssh/id_ed25519_homeserver
Type the key passphrase once.
Step 6: Test#
ssh homeserver
You should be on the server without typing any password.
Done when: ssh homeserver logs you in with no password prompt.
Next: 8. SSH from Windows (if you have a PC), otherwise 10. Lock SSH