How to change the ssh port in Linux servers – Command line option

Secure Shell (SSH) is a cryptographic network protocol for secure data communication, remote command-line login, remote command execution, and other secure network services between two networked computers that connects, via a secure channel over an insecure network, a server and a client (running SSH server and SSH client programs, respectively).
The default value for ssh port is 22. We can change the port value by editing its configuration file.
SSH configuration file.

# /etc/ssh/sshd_config

How to change the ssh port through command line?
Step 1: Open the SSH configuration file by using your favorite editor.

# vi /etc/ssh/sshd_config

Step 2: By default the port value is commented(Using default port #22) in SSH conf file. Uncomment the line and edit the port value to new.

# vi /etc/ssh/sshd_config
------
# Port 22
Port 2929
------

Step 3: Restart the SSH daemon

# service sshd restart
# /etc/init.d/sshd restart

For a cPanel server you can also use this script for restarting the SSH service.

# /scripts/restartsrv_sshd

That’s it. Now your server is more secure than the default SSH.

Related Links:
How to change cpanel port through command line
How to change the apache port via command line in cpanel
How to change ftp port – cpanel

Arunlal Ashok

Linux Cloud Infrastructure / DevOps Engineer. I'm dealing Linux servers since 2012. I started this blog to share and discuss my ideas.

Always happy for an open discussion! Write to arun (@) crybit (dot) com. Check about me for more details. About this blog and our strong members, check The team CryBit.com

Leave a Reply

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