Back to tools

What is SSH Config?

The ~/.ssh/config file allows you to configure SSH connections persistently without needing to type all parameters on every connection.

  • Aliases: Use short names to connect (e.g., ssh my-server instead of ssh -p 22 [email protected])
  • ProxyJump: Connect to internal servers through a bastion/jump host
  • Keep-alive: Keep connections alive with ServerAliveInterval
  • Security: Use StrictHostKeyChecking to verify host keys

Example: Connection with Jump Host

To connect to an internal server through a bastion server:

  1. Configure the bastion server as a separate host in ~/.ssh/config
  2. On the internal server, use ProxyJump bastion to indicate the connection must go through the bastion

Now you can connect with: ssh internal-server

Frequently Asked Questions

How to configure ~/.ssh/config to connect to multiple servers easily?

Edit or create `~/.ssh/config` with Host blocks for each server. Each block defines an alias (`Host`), address (`HostName`), user (`User`), port (`Port`) and SSH key (`IdentityFile`). Example: `Host web-prod HostName 203.0.113.10 User deploy Port 22 IdentityFile ~/.ssh/id_ed25519`. After configuration you simply type `ssh web-prod` instead of the full command. Set file permissions to 600 with `chmod 600 ~/.ssh/config` or SSH will ignore it for security reasons.

What is a Jump Host or ProxyJump in SSH and how to configure it?

A Jump Host (bastion) is an intermediate server used to reach internal servers without public IP addresses. In `~/.ssh/config`, use `ProxyJump user@bastion`. Example: `Host internal HostName 10.0.1.50 User admin ProxyJump bastion.company.com`. When you run `ssh internal`, SSH automatically connects through the bastion and jumps to the target. This prevents exposing internal servers to the Internet and centralizes authentication at a single entry point.

How to set different SSH keys per server in ~/.ssh/config?

Use the `IdentityFile` directive inside each Host block to assign a specific SSH key to each server. Example: `Host github.com HostName github.com User git IdentityFile ~/.ssh/id_ed25519_github` and `Host server HostName 192.168.1.100 User root IdentityFile ~/.ssh/id_rsa_work`. This is essential when managing multiple providers or environments with different key pairs, preventing authentication errors from using the wrong key.

How to prevent SSH connections from freezing or timing out?

To prevent SSH connections from freezing due to inactivity, add to `~/.ssh/config`: `Host * ServerAliveInterval 60 ServerAliveCountMax 3`. The `ServerAliveInterval` directive sends a keepalive packet every 60 seconds from the client to the server. `ServerAliveCountMax 3` determines how many keepalives can fail before disconnecting. If the server also has `ClientAliveInterval` configured, the connection becomes bidirectionally resilient to NAT and firewall timeouts.