How to Set SSH Port in Ubuntu?


How to Set SSH Port in Ubuntu?

Secure Shell (SSH) is a crucial component for accessing and managing remote servers. Changing the default SSH port adds an extra layer of security to your Ubuntu server. In this guide, we'll walk you through the steps to set a custom SSH port on your Ubuntu system, enhancing your server's security.

Why Change the SSH Port?
The default SSH port is 22, and while it's secure, changing it can help thwart potential attackers who often target this port. By setting a custom port, you make it more difficult for unauthorized users to gain access.

Step 1: Connect to Your Server
Open a terminal window and connect to your Ubuntu server using your preferred method, such as SSH. If you're not already logged in, enter your credentials.

ssh your_username@your_server_ip

Step 2: Backup SSH Configuration File
Before making changes, it's essential to create a backup of the SSH configuration file. This way, you can revert to the original settings if needed.

sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config_backup

Step 3: Open the SSH Configuration File
Now, open the SSH configuration file using a text editor. You can use nano, vim, or any other editor of your choice.

sudo nano /etc/ssh/sshd_config

Step 4: Locate the Port Configuration
Look for the line that specifies the SSH port. It typically appears as:

Port 22

Change the port number to your desired custom port, for example:

Port 2222

Save the changes and exit the text editor.

Step 5: Restart the SSH Service
To apply the changes, restart the SSH service.

sudo service ssh restart

Step 6: Update Firewall Rules
If you are using a firewall, update it to allow traffic on the new SSH port.

sudo ufw allow 2222
sudo ufw reload

Replace "2222" with your chosen port.

Step 7: Test the Connection
Open a new terminal window and try connecting to your server using the new port.

ssh -p 2222 your_username@your_server_ip

Replace "2222" with the custom port and "your_username" and "your_server_ip" with your actual credentials and server IP.

Congratulations! You've successfully set a custom SSH port on your Ubuntu server, enhancing its security. Remember to update your SSH client configurations to use the new port for future connections.

Related Searches and Questions asked:

  • How to Access SSH from Ubuntu Terminal?
  • How to Create SSH in Ubuntu?
  • How to Start SSH on Command Line?
  • Unlocking the Power of SSH: A Guide to Accessing SSH from Ubuntu Terminal
  • That's it for this topic, Hope this article is useful. Thanks for Visiting us.