> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.

# How to Change the SSH Port on the VPS

This guide explains how to change the default SSH port on your server and update the required firewall settings so that SSH access continues to work.

:::warning

Follow the steps below exactly as written, and make sure the new SSH port is not already in use on the system.

Keep your current SSH session open until you have successfully connected using the new SSH port. This helps prevent you from being locked out if the SSH configuration or firewall settings are incorrect.

:::

## Change the SSH Port


### Open the SSH configuration file
```bash
nano /etc/ssh/sshd_config
```
### Change the port
Find the line that says `Port 22` and change it to your desired SSH port. Replace `<SSH port Here>` with the port number:
```
Port <SSH port Here>
```
### Save the file and restart SSH
Save the file, then restart the SSH service:
```bash
service sshd restart
```
### Connect using the new port
The next time you SSH into your VPS or server, specify the port you set:
```bash
ssh username@hostname.com -p <SSH port Here>
```

## Update Your Firewall Configuration

Use the section below that matches the firewall on your system. In the commands, change `22` to the new port you set above, and then run them.

### UFW

UFW is used primarily on Ubuntu-based systems.

```bash
ufw allow 22
```

### firewalld

firewalld is primarily used on CentOS 7.

```bash
firewall-cmd --zone=public --add-port=22/tcp --permanent
firewall-cmd --reload
```

### iptables

iptables is commonly used on systems such as CentOS 6 and Debian.

```bash
iptables -A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
service iptables save
service iptables reload
```
