Skip to main content

4.0 SSH Configuration File


The SSH configuration file is used to control the behavior of the SSH client and server, respectively. Client configuration (which is the focus for this document) allows users to define preferences for SSH connections, such as default usernames, key files, ports, and more.

Creation
  1. Locate the .ssh folder
  2. Create a new file in the folder and rename it "config" (make sure to not have any extension)
Common Directives

1. Defining Hosts
The Host directive allows users to create shortcuts for SSH connections.

Host [SERVER]
    HostName [IP ADDRESS]

e.g. Instead of typing ssh user@[IP ADDRESS], users can simply type: ssh server-name

2. Specifying a Username
If the remote username is different from the local one.

Host [SERVER]
    User [USER]

e.g. Now, ssh myserver will default to myuser@[IP ADDRESS]

3. Setting a Custom SSH Port
By default, SSH uses port 22, but some servers use custom ports for security.

Host [SERVER]
    Port [PORT]

e.g. Now, ssh myserver will connect to 10.10.1.100 on port 1666

4. Local Port Forwarding
Allows a user to securely tunnel traffic from a local machine to a remote server through SSH.

LocalForward [local_port] [destination_host]:[destination_port]

EXAMPLE:

Host pi-club-is-cool
    HostName raspberrypiclub.org
    User lilian
    LocalForward 8006 10.10.10.50:8006
  • When you connect using ssh pi-club-is-cool, SSH will:
    • Log in to raspberrypiclub.org as user lilian
    • Forward your local port 8006 to 192.168.1.18:8006 through the SSH connection
  • Any requests made to localhost:8006 on your local machine will be securely sent to 10.10.10.50:8006 via raspberrypiclub.org


Last Updated: 3/5/2025
Contributed by: Lilian