Skip to main content

Host-Specific Configuration File

Instead of typing long SSH commands every time, you can define connection settings in a config file located at ~/.ssh/config. Each host entry acts as an alias for a full SSH command.
nano ~/.ssh/config
You can find the full list of available SSH configuration options in the ssh_config manual.

Configuration File Format

# Apply settings to all hosts
Host *
  ServerAliveInterval 180
  StrictHostKeyChecking no
  UserKnownHostsFile /dev/null

# Define a host alias with full connection details
Host <remote-alias>
  HostName <remote-host/ipaddress>
  Port <port-number>
  User <username>

# Example: connect to server1 with 'ssh server1'
Host server1
  HostName 192.168.0.1
  Port 22
  User karchunt
With the example above, you can connect to server1 simply by running:
ssh server1

Configuration Directives

DirectiveDescription
Host *Applies settings to all hosts
Host <remote-alias>A custom name you can call anything you like
ServerAliveIntervalSends a keep-alive packet to the server at this interval (in seconds). Set to 180 to ping every 3 minutes and keep the connection open.
StrictHostKeyCheckingWhen set to no, disables host key checking and automatically adds new hosts to known_hosts
UserKnownHostsFileSetting to /dev/null suppresses warnings about new or changed hosts
HostNameThe actual remote hostname or IP address
PortThe port number used to connect
UserThe username used to authenticate
Setting StrictHostKeyChecking no and UserKnownHostsFile /dev/null disables host verification. Only use this in trusted or development environments, as it removes protection against man-in-the-middle attacks.

Build docs developers (and LLMs) love