voodish logo
tweet rss book of faces Linked In

Change SSH Port in CentOS Linux

centos.jpg

How to change SSH port from the standard 22 to, for example 339 in CentOS Linux. Although this method helps to stop the majority of opportunistic breakin attempts (cleans your log files up nicely too) it is by no means a complete solution. You should also restrict SSH access to a single IP address, look at /etc/hosts.allow and /etc/hosts.deny - also no online server should be without a firewall.

To change the SSH Port address, using 339 as an example, do the following:

Open the sshd configuration file with your favorite editor

vi /etc/ssh/sshd_config

Find

#Port 22

Replace this with (note the removal of the hash # sign)

Port 339

Find

#Protocol 2,1

Replace this with (again note the removal of the hash # sign)

Protocol 2

Save the file: in vi, use SHIFT ZZ (in nano, press ctrl+x , press y and enter)
Restart SSHD: service sshd restart

SSH will now only allow logins on port 339 for V2 Clients
Make sure to update any Firewall that you may have installed with the new port number.

For APF Firewall this can be found in: vi /etc/apf/conf.apf
Note: Some servers may require a reboot before the changes will take place, but restarting sshd is usually sufficient.

Related Articles

Comments RSS Feed

1 Comments

  1. win77 August 20, 2010

    Cheers, one extra step, it all helps :)

  2. Go to Top of the page

Leave a comment