Centos: How to change SSH Port

ssh nano
In order to secure your server, ROOT access. You should consider to change your default SSH port (Port 22) to NON-Standard port. And you make sure that new SSH Port is allowed by your server fireWall.

Simple Steps:

1. Use ssh client such as Putty to log in to your server with old port (default 22).

2. Change SSH config file /etc/ssh/sshd_config

nano /etc/ssh/sshd_config

If nano editor is not installed on server, use this command to install it

yum install nano

Use vi command instead

vi /etc/ssh/sshd_config

Find this line:

Port 22

Change to your own port and uncomment that line. Example:

Port 1111

Then open new PORT on your server. If you use CSF firewall, just log in to WHM and open CSF control panel then edit TCP_IN port.

3. Restart SSH:

service sshd restart

DONE, your SSH port is changed. You are required to use new Port to login to root server next time.

Note: U can also disable Root logins.

Find this line:

PermitRootLogin yes

Change to

PermitRootLogin no

Then restart SSH

service sshd restart

If you need root access, login as a normal user and use the su command.

More info about Secure SSH at centos.org (link)

Written on 13 April 2012

Share your thoughts