SSH (Secure Shell) is a protocol used for secure remote login to a server or computer. By default, SSH runs on port 22, but changing the port is a good security measure to prevent unauthorized access to your Ubuntu Server. In this blog post, we will go through the steps to change the SSH port on Ubuntu Server.
Step 1: Connect to your Ubuntu Server
First, connect to your Ubuntu Server via SSH using the current port (22). You can use any SSH client such as PuTTY or the built-in terminal on macOS or Linux.
Step 2: Edit the SSH configuration file
Next, you need to edit the SSH configuration file to change the default port. The SSH configuration file is located at
/etc/ssh/sshd_config. You can use any text editor such as nano or vim to edit the file.
To open the file in nano, run the following command:
sudo nano /etc/ssh/sshd_config
Step 3: Change the SSH port
In the SSH configuration file, find the line that specifies the port and change the port number to the one you want to use. For example, if you want to change the SSH port to 2222, find the line that says
#Port 22 and change it to
Step 4: Save and close the file
Once you have made the changes, save and close the file. In nano, you can do this by pressing
Ctrl + X, then
Y, and finally
Step 5: Restart the SSH service
To apply the changes, you need to restart the SSH service. Run the following command to restart the SSH service:
sudo systemctl restart sshd
Step 6: Test the new SSH port
Finally, test the new SSH port by connecting to your server using the new port number. For example, if you changed the port to 2222, run the following command to connect to your server:
ssh user@server_ip -p 2222
user with your username and
server_ip with your server’s IP address or hostname.
In this blog post, we have gone through the steps to change the SSH port on Ubuntu Server. Changing the SSH port is a simple but effective security measure to prevent unauthorized access to your server. Make sure to remember the new port number and update your firewall settings accordingly.