# How to Connect to a Linux Server Using SSH

Secure Shell (SSH) is a widely used protocol for secure passwordless connection to a remote [Linux server](https://www.cherryservers.com/bare-metal-dedicated-servers/linux-dedicated-servers) from any operating system, including Windows, Linux, or macOS. This guide walks you through the steps for connecting via SSH from different platforms.

Before you begin, ensure that you have your credentials, such as username and password, and the necessary privileges to access the server, and check if your server uses a non-standard SSH port. You will need to specify this with the -p option in your SSH command.

## Instructions to Connect to Your Linux Server with SSH
### Instructions to Connect to Your Linux Server with SSH from Linux or macOS
1. Open the Terminal:
   - For Linux: Press Ctrl + Alt + T, or search for "Terminal" in your applications menu.
   - For macOS: Open Spotlight using Command + Space, type "Terminal" and press Enter.
2. Enter the SSH command.

   In the terminal, use the following command to initiate an SSH connection, replacing *"username"* with the username you want to log in with, typically root, and replace *"IP_address"* with the actual IP address or host name of your Linux server:
   ```bash command
   ssh username@ip_address
   ```
   Example:
   ```bash command
   ssh root@5.199.162.89
   ```
   Returns:
   ```bash output
   12:17:30 user@CherryServers ~
   
   ssh root@5.199.162.89
   The authenticity of host '5.199.162.89 (5.199.162.89)' can't be established.
   ED25519 key fingerprint is SHA256:A8DixBg9qB+xQFhpusH7KpLE/UNLZMn12N2JAkQyfQ.
   This key is not known by any other names
   Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
   Warning: Permanently added '5.199.162.89' (ED25519) to the list of known hosts.
   ```
3. Provide your password.

   After running the SSH command, you will be asked to enter your password. Type the password carefully and press Enter. Please note that for security reasons the password won't appear on the screen while typing for security reasons, but your input is still being recorded.
   ```bash output
   root@5.199.162.89's password:
   ```
4. Specify a custom SSH port, if applicable. 

   If your server is using a port other than the default SSH port (22), include the *-p* flag followed by the correct port number:
   ```bash command
   ssh username@ip_address -p custom_port
   ```
   Replace custom_port with the port number your server's SSH service uses.
   Example:
   ```bash command
   ssh user@5.199.162.89 -p 2222
   ```
5. Access the Server.
 
   After successful authentication, you will be connected to the remote server, and you can start executing commands.
   ```bash output
   Welcome to Ubuntu 22.04.5 LTS (GNU/Linux 5.15.0-119-generic x86_64)
   
   Documentation: https://help.ubuntu.com
   
   Management: https://landscape.canonical.com
   
   Support: https://ubuntu.com/pro
   
   System information as of Mon Oct 7 12:51:26 EEST 2024
   
   System load: 0.0 Processes: 87
   Usage of /: 7.4% of 19.20GB Users logged in: 0
   Memory usage: 19% IPv4 address for eth0: 5.199.162.89
   Swap usage: 0%
   
   Expanded Security Maintenance for Applications is not enabled.
   
   0 updates can be applied immediately.
   
   Enable ESM Apps to receive additional future security updates.
   See https://ubuntu.com/esm
   or run: sudo pro status
   
   The list of available updates is more than a week old.
   To check for new updates run: sudo apt update
   
   The programs included with the Ubuntu system are free software;
   the exact distribution terms for each program are described in the
   individual files in /usr/share/doc/*/copyright.
   
   Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
   applicable law.
   ```
###  Instructions to Connect to a Linux Server from Windows
On Windows, SSH connections can be made using either the built-in Windows terminal (available on Windows 10 and later), or third-party applications such as PuTTY.
#### Option A: Using Windows Terminal (or PowerShell)
1. Open Windows Terminal or PowerShell.
   - Press Windows + X, and select "Windows Terminal" or "PowerShell" from the menu.
   - Alternatively, search for Windows Terminal or PowerShell in the Start menu.
2. Enter the SSH command.
   
   In the terminal, run the following command, replacing "*IP_address*" with the IP address or host:
   ```cmd command
   ssh username@ip_address
   ```
   Example:
   ```cmd command
   ssh root@5.199.162.89
   ```
   ```cmd output
   C:\Users\Cherry>ssh root@5.199.162.89
   The authenticity of host '5.199.162.89 (5.199.162.89)' can't be established.
   ECDSA key fingerprint is SHA256:Gj7l1wurcTXy+dmUwkNANSq9mA+vInWmCBDVlxrh0M.
   Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
   Warning: Permanently added '5.199.162.89' (ECDSA) to the list of known hosts.
   ```
3. Provide your password. 

   After entering the SSH command, you will be prompted to type your password. Enter it and press Enter. Once authenticated, you will be logged into the Linux server.
   ```cmd output
   root@5.199.162.89's password:
   ```
4. Specify a Custom SSH Port.
   
   If your server uses a non-default port, append the *-p* flag to the command with the appropriate port number:
   ```cmd command
   ssh username@ip_address -p custom_port
   ```
#### Option B: Using PuTTY
PuTTY is a popular third-party SSH client for Windows users.
1. Download and install PuTTY: Download PuTTY from the official website: https://www.putty.org and install it.
   ![](https://www.cherryservers.com/v3/assets/documentation/how-to/cls-1.png)
2. Launch PuTTY: Open PuTTY from the Start menu or a desktop shortcut.
3. Enter the server's IP address:
   - In the Host Name (or IP address) field, input the server's IP address (e.g., 5.199.162.89).
   ![](https://www.cherryservers.com/v3/assets/documentation/how-to/cls-2.png)
   - Ensure the SSH connection type is selected and the port is set either to 22, or your custom port, if applicable.
   ![](https://www.cherryservers.com/v3/assets/documentation/how-to/cls-3.png)
4. Click the "Open" button to start the connection.
5. Provide your username and password: When the terminal window appears, it will prompt you for your username and password. Enter the credentials to access the server.
   ![](https://www.cherryservers.com/v3/assets/documentation/how-to/cls-4.png)

## Closing the SSH Connection
Once you have finished working on the server, it’s essential to close the SSH session properly.
1. Type the Exit command. 
   
   To log out of the server and close the connection, type the following command and press "Enter":
   ```bash command
   exit
   ```
2. Session Closed: The terminal window will close, or you’ll be returned to your local machine’s terminal.