Monday, March 23, 2009

change the ssh port

It is advisable to change your ssh port from defaul 22 to something higher to lower your chances of brute force attacks

Below are the steps to change the ssh port.

1. Update /etc/ssh/sshd_config file, line 13 (it might be different in your file):

old line:
Port 22
Change it to:
Port 18675 # any port number you wish

2. You need to update your /etc/services file to tell that your ssh service will now use a different port. Jump to line number 45 (may be differnt in your file) and change port number:

old line:
ssh 22/tcp # SSH Remote Login Protocol
change it to:
ssh 54545/tcp # SSH Remote Login Protocol

save and exit from the file.

3. Restart your sshd service,
# /etc/init.d/sshd restart

It should go smooth. You have to specify port number every time you use ssh or scp or any other service which use ssh in any way.

If your server or machine is behind a firewall, you must open the newly assigned port in your firewall.

4. Open a port in firewall

#cd /etc/sysconfig

#vi iptables

add the following line(just change port number in place of 1867)
-A RH-Firewall-1-INPUT -m tcp -p tcp --dport 1867 -j ACCEPT

save and restart iptables service.
=====================================================

How to open a port in APF
Open port 2346 using APF

Login as the root

Open config file /etc/apf/conf.apf
# vi /etc/apf/conf.apf
Find line that read as follows:
IG_TCP_CPORTS
Add port 2346 (keep all other ports):
IG_TCP_CPORTS="2346,22,25,53,80,443,993,904,...."
Close and save the file. Restart firewall:
# /etc/init.d/apf restart