Linux Command Reference ยท Special Files and Directories
~/.ssh files and sshd_config
Reference for SSH files: ~/.ssh/config host blocks, authorized_keys, known_hosts, key files with required permissions, and the main sshd_config options.
SSH keeps its settings in a few small text files. On the client side, everything lives in ~/.ssh/: config (per-host settings), known_hosts (fingerprints of servers you trust), and your private and public keys. On the server side, /etc/ssh/sshd_config controls the daemon, and each user's ~/.ssh/authorized_keys lists the public keys allowed to log in.
SSH is strict about permissions. If your private key or the .ssh directory is writable by others, the client or server ignores it with a warning. The usual modes are 700 for ~/.ssh, 600 for private keys, config and authorized_keys, and 644 for public keys.
Host web
HostName 203.0.113.10
User deploy
IdentityFile ~/.ssh/id_ed25519
Try it
The sandbox has an ssh client but no server, no network and no keys worth using, so these examples build the file layout in a temporary folder and query a config file in Bash.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Syntax
Client ~/.ssh/config is made of Host blocks. For each option the first value found wins, so put specific hosts before Host *.
| Option | Description |
|---|---|
Host pattern ... |
Starts a block for matching names (* and ? allowed). |
HostName |
The real address or DNS name to connect to. |
User, Port |
Login name and TCP port. |
IdentityFile |
Private key to try; add IdentitiesOnly yes to use only that key. |
ProxyJump |
Hop through a bastion host (-J). |
ServerAliveInterval |
Seconds between keep-alive messages. |
ControlMaster, ControlPath, ControlPersist |
Share one connection among sessions. |
Server /etc/ssh/sshd_config options often changed:
| Option | Description |
|---|---|
Port |
Listening port. |
PermitRootLogin |
no, prohibit-password or yes. |
PasswordAuthentication |
no allows only keys. |
PubkeyAuthentication |
Enable key login (default yes). |
AllowUsers, AllowGroups |
Restrict who may log in. |
AuthorizedKeysFile |
Where keys are read from (default .ssh/authorized_keys). |
Check the syntax before reloading with sshd -t.
Usage notes
authorized_keyslines hold one public key each, optionally with restrictions in front, such ascommand="/usr/bin/backup",no-pty ssh-ed25519 AAAA... label.known_hostsis how SSH detects a changed server key. A "REMOTE HOST IDENTIFICATION HAS CHANGED" warning means either a reinstall or an attack; remove the old line withssh-keygen -R hostonly after you checked.- Key types: prefer Ed25519 (
ssh-keygen -t ed25519). Protect private keys with a passphrase andssh-agent. - Safe server changes: keep an existing session open, run
sshd -t, reload the service, then test a second login before closing the first. Includepulls in other config files, useful for~/.ssh/config.d/*.- Debugging:
ssh -v hostshows which files and keys are used; the server logs to the journal or/var/log/auth.log. - Never copy a private key to a server; copy the public key with
ssh-copy-id. - Options are case-insensitive, arguments (paths, user names) are not.