C.W.K.
Stream
Lesson 01 of 08 · published

SSH Basics: Keys and Agent

~13 min · ssh, ed25519, ssh-agent

Level 0Window Tourist
0 XP0/95 lessons0/14 achievements
0/100 XP to next level100 XP to go0% complete

Why keys, not passwords

SSH keys replace passwords with cryptographic key pairs. The private key stays on your machine; the public key goes on every server you log into. The server checks that you hold the private key without ever seeing it. Faster, safer, scriptable.

Generate

ssh-keygen -t ed25519 -C 'me@laptop'

Ed25519 is the modern default — small, fast, secure. RSA 4096 is the fallback for systems too old to know ed25519. Accept the default path (~/.ssh/id_ed25519) and set a passphrase.

Copy your public key to a server

ssh-copy-id user@server      # appends to remote ~/.ssh/authorized_keys
# If ssh-copy-id is missing on macOS
cat ~/.ssh/id_ed25519.pub | ssh user@server 'mkdir -p ~/.ssh; cat >> ~/.ssh/authorized_keys'

ssh-agent — type the passphrase once

The agent caches your unlocked private key in memory. With it, you type the passphrase once per session and ssh / scp / git all use the key transparently.

eval "$(ssh-agent -s)"
ssh-add --apple-use-keychain ~/.ssh/id_ed25519   # macOS — store in Keychain
ssh-add -l                                       # list loaded keys

macOS auto-starts the agent. Add UseKeychain yes and AddKeysToAgent yes in ~/.ssh/config under Host * to make passphrase prompts a one-time annoyance.

Permissions

chmod 700 ~/.ssh
chmod 600 ~/.ssh/id_ed25519 ~/.ssh/config
chmod 644 ~/.ssh/id_ed25519.pub ~/.ssh/known_hosts

If anything is more permissive, ssh refuses the key.

Code

Generate + deploy a key·bash
ssh-keygen -t ed25519 -C 'me@$(hostname -s)'
# Verify
cat ~/.ssh/id_ed25519.pub
# Push to a server
ssh-copy-id user@server.example.com
# Test
ssh user@server.example.com 'echo ok'
macOS-friendly ssh config block·bash
cat >> ~/.ssh/config <<'EOF'
Host *
  UseKeychain yes
  AddKeysToAgent yes
  IdentitiesOnly yes
  ServerAliveInterval 60
EOF
chmod 600 ~/.ssh/config

External links

Exercise

Generate a key: ssh-keygen -t ed25519 -C 'me@laptop'. Add the host-* block to .ssh/config. Run ssh-add --apple-use-keychain ~/.ssh/id_ed25519. Test on any server you have access to: ssh user@server.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.