How to Change the SSH Port in Ubuntu Linux Print

  • 27

SSH (Secure Shell) is an a shield tool for remote server control in Linux-based operating systems like Ubuntu. It enables secure access to remote servers.

SSH uses the default port 22, which is easily targeted by attackers. Thus, you can change the port to safeguard your machine from these types of cyber threats.

This informative post will show you how to modify the SSH port on your Ubuntu Linux server.

How Do I Change the SSH Port in Ubuntu Linux?
Follow these instructions to change the current SSH port on a Linux machine.

Step 1: Check the current SSH port.

Before we begin the process of changing SSH ports on Linux, let's examine the current SSH port on your Ubuntu system.

sudo ss -tulpn | grep ssh

The given command displays your system's current SSH port, such as port 22.

Step 2: Check SSH Service Connectivity.

Now, ensure that your system's SSH service is active. Run the following command in your terminal to confirm SSH service connectivity:

sudo systemctl status ssh

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]

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

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

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

Step 7: Verify Port After Changes

Recheck the SSH port after changes through the command:

sudo ss -tulpn | grep ssh

After completing the aforementioned procedures, you have successfully changed the SSH port on your Ubuntu machine.


Was this answer helpful?

« Back

Powered by WHMCompleteSolution