How to Change the SSH Port in Ubuntu Linux

SSH (Secure Shell) is a powerful tool for remote server management in Linux-based operating systems including Ubuntu. It is used to access remote servers securely. 

SSH operates on the default port 22, which can be easily targeted by attackers. Thus, you can modify the port to protect your system from such kinds of cyber attacks.

Through this educational post, you can change SSH port on your Ubuntu Linux system.

How to Change the SSH Port in Ubuntu Linux?

Modify the current SSH port through these steps in a Linux-based system.

Step 1: Check the Current SSH Port

Before initiating the process of changing SSH port on Linux, let’s check the current SSH port on your Ubuntu system:

sudo ss -tulpn | grep ssh
sudo ss -tulpn

The provided command will display the current SSH port, such as port 22, on your system.

Step 2: Confirm SSH Service Connectivity

Now, make sure that the SSH service is active on your system. Execute the command in your terminal to confirm SSH service connectivity:

sudo systemctl status ssh
sudo systemctl status ssh

This command will provide information about the SSH service, including its status (running/stop).

Step 3: Connect to the Remote Server via SSH 

For modifications in the SSH configuration file, connect to the remote server through the command:

ssh [email protected]
ssh techpub@127.0.0.1

Don’t forget to replace the username “techpub” with your preferred username.

Step 4: Access SSH Configuration File

Utilize the following command to access the SSH configuration file in a Nano text editor:

sudo nano /etc/ssh/sshd_config
sudo nano /etc/ssh/sshd_config

Step 5: Modify SSH Port 

Inside the SSH configuration file, locate the SSH port usually named #Port 22. Remove the “#” symbol at the beginning, and modify the port number to your choice like Port 2222:

Port 2222
Port 2222

Save the changes after modification and close by pressing Ctrl + X.

Step 6: Exit the Remote Server

Run the Exit command to logout and close the remote server:

exit
exit

Step 7: Verify Port After Changes 

Recheck the SSH port after changes through the command:

sudo ss -tulpn | grep ssh
sudo ss -tulpn

Upon following the aforementioned steps, you have successfully changed the SSH port on your Ubuntu system.

Conclusion

In this article, you have learned how to change SSH port on Ubuntu. To modify the port, first, connect to the particular server and then open the configuration file via the command: “sudo nano /etc/ssh/sshd_config”. Locate the #port 22, a default SSH port, and replace the port number with your desired one.

To modify the port in Ubuntu, connect to the remote server, access the configuration file via sudo nano /etc/ssh/sshd_config, and change the default port 22. Rent a server with dependability and scalable features tailored to accommodate your expanding requirements. Discover our range of VPS plans to identify the ideal solution for your needs.

FAQ

Can I Change the Default SSH Port in the Linux system?
Why change the SSH port in Ubuntu Linux?
Can I check the current SSH port on my Ubuntu system?

Related Post

How to Enable or Disable IPV6 on Ubuntu Linux

IPv6, also known as Internet Protocol version 6, offers...

How to Check Disk Free Space on Linux

Checking and managing free space on your system disk is...

How to Install SQLite on Ubuntu 22.04

As a system administrator or developer, you are likely ...

How to Install cPanel on Ubuntu

cPanel is a web-based control panel software that provi...

How to Install Redmine on Ubuntu 22.04

Redmine is a flexible project management web applicatio...

How to Install Apache Cordova on Ubuntu

For mobile and web developers, creating hybrid applicat...

Leave a Comment