C.W.K.
Stream
Lesson 09 of 10 · published

SSH Config

~10 min · ssh, config, tunnel

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

~/.ssh/config — your remote address book

Without config, every ssh command needs the full host, user, port, key path. ~/.ssh/config turns ssh -i ~/.ssh/work_id -p 2222 alice@server.example.com into ssh work. Same for scp, rsync, and any tool that uses ssh under the hood.

The shape

Host work
  HostName server.example.com
  User alice
  Port 2222
  IdentityFile ~/.ssh/work_id_ed25519
  IdentitiesOnly yes

Host *.internal
  User root
  ProxyJump bastion.internal

Indent the directives. Patterns (*.internal, 10.0.*) match by host alias. Order matters — earlier blocks win on conflict.

Common directives

  • IdentityFile ~/.ssh/foo — which key to use.
  • IdentitiesOnly yes — try only that key (avoids ssh-agent spamming all your keys until the server locks you out).
  • ProxyJump bastion — go through a jump host.
  • ForwardAgent yes — forward your local agent (use carefully).
  • LocalForward 5900 localhost:5900 — auto-tunnel on connect.
  • ControlMaster auto, ControlPath ~/.ssh/cm-%r@%h:%p — share a single connection between commands. Speeds up rsync loops massively.

Permissions matter

~/.ssh must be 700, files inside 600. Loose permissions make ssh refuse to use the key ("Permissions are too open"). One chmod 700 ~/.ssh; chmod 600 ~/.ssh/* after cloning a dotfiles repo saves an hour of debugging.

Test fast

ssh -T host tries to authenticate without opening a shell. ssh -v host shows every step the client takes. Use these for debugging.

Code

Bootstrap an SSH config·bash
mkdir -p ~/.ssh && chmod 700 ~/.ssh
cat > ~/.ssh/config <<'EOF'
Host *
  ServerAliveInterval 60
  ServerAliveCountMax 3
  ControlMaster auto
  ControlPath ~/.ssh/cm-%r@%h:%p
  ControlPersist 1h

Host server
  HostName 192.168.1.10
  User you_username
  IdentityFile ~/.ssh/id_ed25519
  IdentitiesOnly yes
EOF
chmod 600 ~/.ssh/config

External links

Exercise

Open or create ~/.ssh/config. Add a Host * block with ServerAliveInterval 60. Add one specific Host. chmod 700 ~/.ssh; chmod 600 ~/.ssh/config. Test with ssh -T <host>.

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.