The ssh config file
The options in a client config file that save typing: host names, users, keys, jump hosts and keep-alives.
Computers keep client settings in ~/.ssh/config. Each Host block gives a short name and its options.
Host prod
HostName prod.example.com
User jsmith
Port 2222
IdentityFile ~/.ssh/id_ed25519
IdentitiesOnly yes
ServerAliveInterval 30
Host internal-*
ProxyJump [email protected]
ssh prod then means "connect to prod.example.com, port 2222, as jsmith, with that key". scp and sftp read the same file; see Do scp and sftp use ~/.ssh/config? Host aliases, -F and -P.
The options you will use
HostName: the real name or address.User,Port: the login and the port.IdentityFile: which key to use. WithIdentitiesOnly yesonly this key is offered, which avoids "too many authentication failures".ProxyJump: reach the host through a jump host.ForwardAgent: agent forwarding. Leave it off unless you need it.LocalForward,RemoteForward,DynamicForward: port forwards.ServerAliveIntervalandServerAliveCountMax: send keep-alive messages so an idle connection is not dropped by a firewall, and a dead one is noticed.StrictHostKeyChecking: what to do with an unknown or changed host key.Include: read more files.ControlMaster,ControlPath,ControlPersist: reuse one connection for later sessions. See SSH ControlMaster: reuse one connection with ControlPath and ControlPersist.
Patterns work: Host *.example.com or Host internal-*. The first value found wins, so put specific blocks before Host *.
Testing
ssh -G prod show the settings that will be used
ssh -v prod print each step of the connection
If ssh stops with "Bad owner or permissions" on this file, see SSH "Bad owner or permissions on ~/.ssh/config": what it checks and how to fix it. If it stops with "Bad configuration option", see SSH "Bad configuration option" in ~/.ssh/config or sshd_config.
In an app
Phone and tablet apps do not read this file. They keep the same settings in their own profile screens: host, user, port, key, jump host and forwards. The meaning is the same.
Related
- Jump hosts
- Port forwarding
- How SSH works
- Do scp and sftp use ~/.ssh/config? Host aliases, -F and -P
- Use a different SSH key for the jump host and the target
- SSH "Bad owner or permissions on ~/.ssh/config": what it checks and how to fix it
- SSH ControlMaster: reuse one connection with ControlPath and ControlPersist
- SSH "connection is not using a post-quantum key exchange algorithm"
- SSH "Bad configuration option" in ~/.ssh/config or sshd_config
- Does Mosh read ~/.ssh/config? Host aliases, ports, --ssh and Dropbear