# How to: SSH

# What is SSH?

##### <span style="color: rgb(0, 0, 0);">**Introduction**</span>

<span style="color: rgb(0, 0, 0);">SSH (Secure Shell) is a cryptographic network protocol that enables secure communication between computers over a potentially unsecured network, like the internet. It is primarily used to remotely access and manage servers, devices, and systems. (ง ื▿ ื)ว</span>

##### <span style="color: rgb(0, 0, 0);">**Capabilities of SSH:**</span>

- <span style="color: rgb(0, 0, 0);">**Encrypted Communication**: SSH ensures that data sent between the client (your computer) and the server is encrypted, which protects it from eavesdropping, tampering, or unauthorized access.</span>
- <span style="color: rgb(0, 0, 0);">**Authentication**: SSH uses key-based or password-based authentication to verify the identity of the client and server before establishing a connection. The most secure form is public-key authentication, where a private key on the client is matched with a public key stored on the server.</span>
- <span style="color: rgb(0, 0, 0);">**Command Execution**: SSH allows users to execute commands remotely on a server. For example, you can manage files, install software, or configure system settings as if you were physically at the server, all through the command line.</span>

<span style="color: rgb(0, 0, 0);">*Last Updated: 2/20/2025  
BY: Lilian*</span>

# 1.0 Generate and Add SSH Keys to Github

---

<p class="callout info"><span style="color: rgb(45, 194, 107);">**<span style="color: rgb(35, 111, 161);">\*Any confusion on command syntax/structure can be clarified in</span> <span style="color: rgb(22, 145, 121);">[Legend](https://wiki.raspberrypiclub.org/books/how-to-refer-to-the-documentation/page/legend)</span>**</span></p>

1. <span style="color: rgb(0, 0, 0);">On device you want to ssh with, open a shell (e.g. PowerShell), enter the command below:</span>
    
    
    - <span style="color: rgb(0, 0, 0);">Just press Enter for the prompts</span>
    - <span style="color: rgb(0, 0, 0);">Make sure to note where the SSH keys are being stored</span>
        
        
        - <span style="color: rgb(0, 0, 0);">e.g.) C:\\Users\\\[USER\]\\.ssh\\</span>

```
ssh-keygen -t ed25519
```

<div align="left" dir="ltr" id="bkmrk--1"></div>2. <span style="color: rgb(0, 0, 0);">Navigate to the .ssh folder</span>
3. <span style="color: rgb(0, 0, 0);">Open the public key file (ends in .pub) in Notepad and copy just the key</span>
4. <span style="color: rgb(0, 0, 0);">Add the public SSH key on user’s<span style="color: rgb(22, 145, 121);"> [Github account](https://github.com/)</span></span>
    
    
    - <span style="color: rgb(0, 0, 0);">Click on Github Profile &gt; Settings &gt; SSH and GPG keys &gt; New SSH key</span>

<span style="color: rgb(0, 0, 0);">![](https://lh7-rt.googleusercontent.com/docsz/AD_4nXf2rPALmFykxmKx_W8CiCmvxzBSA4zkLqrjMFuyIO7_hh4ukcmkI0MwViL4zlmv5RqrIh3-JtsM4iJ0nGoVCrNdlu03I8m5R0jWQhgVKv-A0iYHiyGfNFU9hMSH1kylmbZeE7HGAw?key=A7w7-IIrPHtvIEAignbkTKHY)</span>

5. <span style="color: rgb(0, 0, 0);">Paste the public key into user’s Github profile</span>
    
    
    - <span style="color: rgb(0, 0, 0);">Title can be anything (should note what machine it belongs to)</span>
    - <span style="color: rgb(0, 0, 0);">Key type: Authentication Key</span>

<span style="color: rgb(0, 0, 0);">![](https://lh7-rt.googleusercontent.com/docsz/AD_4nXeQyhG1sXX_hvNsfUvNO3KqYSVyRV1YMuXJ3W9CZn3N_j0aAmczzgPxJvK5tP1L7YFq1tW8bzCXFW3oPLQauc37iE3dzpHJb4lbFsJgE5Nxd0Fgfy_RkOdJvlHwn1jGLPp-eU8ZBA?key=A7w7-IIrPHtvIEAignbkTKHY)</span>

<span style="color: rgb(0, 0, 0);">**You should now be able to SSH into the system that has your public keys with machines that hold the corresponding private key!**</span>

<span style="color: rgb(0, 0, 0);">*Last Updated: 2/22/2025  
Contributors: Lilian, Vivian* </span>

# 2.0 Import SSH keys (on Debian Linux)

---

<p class="callout info"><span style="color: rgb(45, 194, 107);">**<span style="color: rgb(35, 111, 161);">\*Any confusion on command syntax/structure can be clarified in</span> <span style="color: rgb(22, 145, 121);">[Legend](https://wiki.raspberrypiclub.org/books/how-to-refer-to-the-documentation/page/legend)</span>**</span></p>

##### <span style="color: rgb(0, 0, 0);">**Importing Personal SSH Keys**</span>

<p class="callout info"><span style="color: rgb(35, 111, 161);">**Applicable to Personal / Home Lab setup**</span></p>

1. <span style="color: rgb(0, 0, 0);">Import the user’s GitHub keys so they can ssh from their computer:</span>
    
    
    - <span style="color: rgb(0, 0, 0);">If any new SSH keys from other devices are added, this command needs to be done again</span>

```
ssh-import-id-gh [GITHUB USERNAME] 
```

##### <span style="color: rgb(0, 0, 0);">**Importing Other User's SSH Keys**</span>

<p class="callout info"><span style="color: rgb(35, 111, 161);">**Applicable to the Raspberry Pi Club servers - allowing other *trusted* users ssh access to a system requires more steps:**</span></p>

1. <span style="color: rgb(0, 0, 0);">In the sys-admin’s shell, ssh into the system (e.g. node, VM, etc.) you want to give access to, and then escalate to superuser:</span>

```
sudo su -
```

2. <span style="color: rgb(0, 0, 0);">Create the new user and then add them to sudoers group:</span>
    
    
    - <span style="color: rgb(0, 0, 0);">Set an easy temporary password for the user (e.g. password)</span>

```
adduser [USER]
usermod -aG sudo [USER]
```

3. <span style="color: rgb(0, 0, 0);">Switch the newly created user account:</span>

```
sudo su [USER] -
```

4. <span style="color: rgb(0, 0, 0);">Import the user’s GitHub keys so they can ssh from their computer:</span>

```
ssh-import-id-gh [GITHUB USERNAME]
```

5. <span style="color: rgb(0, 0, 0);">Have user ssh into the system and change their password into something secure:</span>
    
    
    - <span style="color: rgb(0, 0, 0);">If any new SSH keys from other devices are added, this command needs to be done again</span>

```
passwd
```

<span style="color: rgb(0, 0, 0);">*Last Updated: 2/22/2025  
Contributors: Lilian, Vivian*</span>

# 3.0 Using SSH

---

##### ****SSH into a System****

1. <span style="color: rgb(0, 0, 0);">Open up a new shell (e.g. PowerShell)</span>
2. <span style="color: rgb(0, 0, 0);">Type in the following:</span>

```
ssh [USERNAME]@[IP ADDRESS]
```

****OR****

```
ssh [HOST]
```

****IMAGE SHOWING A SUCCESSFUL SSH ACCESS:****

[![image.png](https://wiki.raspberrypiclub.org/uploads/images/gallery/2025-02/scaled-1680-/Z8Fimage.png)](https://wiki.raspberrypiclub.org/uploads/images/gallery/2025-02/Z8Fimage.png)

<span style="white-space: pre-wrap;"></span>

# 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**