How to Change SSH Port in Linux

Introduction

The majority of web server SSH ports, including AWS and Digital Ocean, are set to 22 by default. You can improve the server’s security by changing the SSH port on any Linux server. I’ll show you how to quickly change the Linux SSH port in this tutorial.

Know about Ports

A port is a logical endpoint for transmitting data across a network. It is a software construct that acts as a communication endpoint for a specific type of network service.

Some common ports:

  • HTTP: Port 80
  • HTTPS: Port 443
  • SSH: Port 22
  • FTP: Port 21
  • SMTP: Port 25
  • DNS: Port 53
  • Telnet: Port 23
  • RDP: Port 3389

In Linux systems, changing the SSH port is simple. Any port from 0 to 65535 can be used. The reserved port number 0 cannot be utilized. On port 22, the default SSH service listens. only this port and a few others.

Step 1: Open SSH Config

To change and update SSH port, edit OpenSSH configuration file

 sudo nano /etc/ssh/sshd_config

Find port 22 in the configuration file. When you locate port 22, remove the comment and replace it with a different nonstandard port, such as 2220. Save the configuration file now.

Search for
Port 22

Replace with
Port 2220

To put changes into effect, restart the SSH daemon now.

 sudo systemctl restart ssh 

Congratulations, your ssh server login port has been successfully changed.

Step 2: Access the Server with New SSH Port

Due to the fact that the SSH daemon is running on a non-standard port, the command-

ssh -p 2220 user@serverIP

We have successfully Changed SSH Port in Linux Kindly report in case you are facing difficulties with following details.

  • OS name
  • OS version
  • Package name
  • Logs – Error / Warning / failed
How to Change SSH Port in Linux

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top