# 4.0 SSH Configuration File

---

<span style="color: rgb(0, 0, 0);">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.</span>

##### ****Creation****

1. <span style="color: rgb(0, 0, 0);">Locate the .ssh folder</span>
2. <span style="color: rgb(0, 0, 0);">Create a new file in the folder and rename it "config" (make sure to not have any extension)</span>

##### ****Common Directives****

****1. Defining Hosts****  
<span style="color: rgb(0, 0, 0); white-space: pre-wrap;">The </span>`<span class="editor-theme-code">Host</span>`<span style="color: rgb(0, 0, 0); white-space: pre-wrap;"> directive allows users to create shortcuts for SSH connections.</span>

```
Host [SERVER]
    HostName [IP ADDRESS]
```

<span style="color: rgb(0, 0, 0); white-space: pre-wrap;">e.g. Instead of typing </span>`<span class="editor-theme-code">ssh user@[IP ADDRESS]</span>`<span style="color: rgb(0, 0, 0); white-space: pre-wrap;">, users can simply type: </span>`<span class="editor-theme-code">ssh server-name</span>`<span style="color: rgb(0, 0, 0); white-space: pre-wrap;"></span>

****2. Specifying a Username****   
<span style="color: rgb(0, 0, 0);">If the remote username is different from the local one.</span>

```
Host [SERVER]
    User [USER]
```

<p class="callout info"><span style="color: rgb(0, 0, 0); white-space: pre-wrap;">e.g. Now, </span>`<span class="editor-theme-code">ssh myserver</span>`<span style="color: rgb(0, 0, 0); white-space: pre-wrap;"> will default to </span>`<span class="editor-theme-code">myuser@[IP ADDRESS]</span>`</p>

****3. Setting a Custom SSH Port****  
<span style="color: rgb(0, 0, 0); white-space: pre-wrap;">By default, SSH uses port </span>`<span class="editor-theme-code">22</span>`<span style="color: rgb(0, 0, 0);">, but some servers use custom ports for security.</span>

```
Host [SERVER]
    Port [PORT]
```

<p class="callout info"><span style="color: rgb(0, 0, 0); white-space: pre-wrap;">e.g. Now, </span>`<span class="editor-theme-code">ssh myserver</span>`<span style="color: rgb(0, 0, 0); white-space: pre-wrap;"> will connect to </span>`<span class="editor-theme-code">10.10.1.100</span>`<span style="color: rgb(0, 0, 0); white-space: pre-wrap;"> on port </span>`<span class="editor-theme-code">1666</span>`</p>

****4. Local Port Forwarding****   
<span style="color: rgb(0, 0, 0);">Allows a user to securely tunnel traffic from a local machine to a remote server through SSH.</span>

```
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
```

- <span style="color: rgb(0, 0, 0); white-space: pre-wrap;">When you connect using </span>`<span class="editor-theme-code">ssh pi-club-is-cool</span>`<span style="color: rgb(0, 0, 0);">, SSH will:</span>
    - <span style="color: rgb(0, 0, 0); white-space: pre-wrap;">Log in to </span>`<span class="editor-theme-code">raspberrypiclub.org</span>`<span style="color: rgb(0, 0, 0); white-space: pre-wrap;"> as user </span>`<span class="editor-theme-code">lilian</span>`
    - <span style="color: rgb(0, 0, 0); white-space: pre-wrap;">Forward your </span>**local port* `<em class="editor-theme-code editor-theme-italic">8006</em>`*<span style="color: rgb(0, 0, 0); white-space: pre-wrap;"> to </span>`<span class="editor-theme-code">192.168.1.18:8006</span>`<span style="color: rgb(0, 0, 0); white-space: pre-wrap;"> through the SSH connection</span>
- <span style="color: rgb(0, 0, 0); white-space: pre-wrap;">Any requests made to </span>**localhost:8006**<span style="color: rgb(0, 0, 0); white-space: pre-wrap;"> on your local machine will be securely sent to </span>**10.10.10.50:8006**<span style="color: rgb(0, 0, 0); white-space: pre-wrap;"> via </span>`<span class="editor-theme-code">raspberrypiclub.org</span>`

---

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