> ## Documentation Index
> Fetch the complete documentation index at: https://gcore.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Change the port for SSH connections

Follow these instructions to modify the SSH port through which you connect to your Linux server.

1. Log in to your server.

2. Navigate to the SSH directory using the following command:

```sh theme={null}
cd /etc/ssh/
```

3. Open the SSH configuration file with root privileges using this command:

```sh theme={null}
sudo nano sshd_config
```

4. Find the **Port** line in the open file and replace the value 22 with the port number you want to use. Also, remove the **#** symbol if it is present before the **Port** line.

<Frame>
  <img src="https://mintcdn.com/gcore/AVlk5NJu0Epwz6C_/images/docs/hosting/virtual-servers/manage/connect/change-the-port-for-ssh-connections/1-port-22.png?fit=max&auto=format&n=AVlk5NJu0Epwz6C_&q=85&s=f9e80fe14879c1364fe502f97b3ba725" alt="terminal" width="823" height="519" data-path="images/docs/hosting/virtual-servers/manage/connect/change-the-port-for-ssh-connections/1-port-22.png" />
</Frame>

<Frame>
  <img src="https://mintcdn.com/gcore/AVlk5NJu0Epwz6C_/images/docs/hosting/virtual-servers/manage/connect/change-the-port-for-ssh-connections/2-port-2233.png?fit=max&auto=format&n=AVlk5NJu0Epwz6C_&q=85&s=4ac0549da3799566d1ef31a6978ecd71" alt="terminal" width="765" height="426" data-path="images/docs/hosting/virtual-servers/manage/connect/change-the-port-for-ssh-connections/2-port-2233.png" />
</Frame>

5. Press **Ctrl+O** to save the changes.

6. Restart the SSH service. For Ubuntu, Debian, or CentOS, use the following command:

```sh theme={null}
sudo systemctl restart ssh
```

For FreeBSD, use:

```sh theme={null}
sudo service sshd restart
```

7. Add a rule to permit traffic exchange on the new port using the command:

```sh theme={null}
sudo ufw allow 2233
```

Replace "2233" with the chosen port.

8. Verify if everything is functioning properly by using the command:

```sh theme={null}
telnet 8.8.8.8 2233
```

Replace "8.8.8.8" with your server IP address, and "2233" with the chosen port.

The output should look like this:

<Frame>
  <img src="https://mintcdn.com/gcore/AVlk5NJu0Epwz6C_/images/docs/hosting/virtual-servers/manage/connect/change-the-port-for-ssh-connections/3-output.png?fit=max&auto=format&n=AVlk5NJu0Epwz6C_&q=85&s=52bf45164913a748e81889d9dab7537d" alt="output" width="590" height="99" data-path="images/docs/hosting/virtual-servers/manage/connect/change-the-port-for-ssh-connections/3-output.png" />
</Frame>

9. Attempt to establish a connection to your server using the new port in a separate window **without closing your current session**. This step is crucial to prevent any potential loss of access to your server. If you encounter difficulties connecting to your server through the new port, revert the port back to 22 and then try again.
