How to change SSH Port on ubuntu ?

From PheonixSolutions
Jump to navigation Jump to search

Introduction

[edit]

Secure Shell (SSH) is a protocol that allows you to securely connect to a remote server or system over an unsecured network. By default, SSH uses port 22 for communication. However, for security reasons, you may want to change the SSH port to a different number. This guide will walk you through the process of changing the SSH port on an Ubuntu server.

Prerequisites

[edit]

Before you begin, ensure that you have:

1. Access to the Ubuntu server with administrative privileges.

2. Basic knowledge of using the command line interface.

3. A text editor installed on your system (e.g., Vi or Nano).

Step-by-Step Guide

[edit]

Step 1: Login to the Server Log in to your Ubuntu server using SSH or through a physical terminal if you have direct access.

Step 2: Edit the SSH Configuration File Open the SSH configuration file, sshd_config, using a text editor. You can use Vi or Nano for this purpose. In this example, we'll use Vi:

 sudo vi /etc/ssh/sshd_config

Step 3: Modify the SSH Port In the sshd_config file, locate the line that begins with #Port 22. Remove the # character to uncomment the line and change 22 to your desired port number. Ensure that the port you choose is not already in use and is not restricted by your network or firewall settings.

Step 4: Reload SSH Service After making the changes, save the file and exit the text editor. Then, reload the SSH service to apply the changes:

 sudo systemctl reload sshd 

Step 5: Test the New SSH Port Attempt to log in to the server using SSH with the new port number:

 ssh username@IP_address -p new_port_number

Replace username with your username, IP_address with your server's IP address, and new_port_number with the port number you specified in the configuration file.

Conclusion

[edit]

Changing the SSH port from the default port 22 to a custom port enhances the security of your server by reducing the likelihood of automated attacks. However, remember to make a note of the new port number as you'll need it for future SSH connections. Additionally, ensure that you have configured your firewall settings to allow incoming connections on the new SSH port.