Link to home
Start Free TrialLog in
Avatar of CahitEy
CahitEy

asked on

Change ssh port

How could i change ssh port of my linux cent os 5.4 final
Avatar of fosiul01
fosiul01
Flag of United Kingdom of Great Britain and Northern Ireland image

in /etc/ssh/sshd_config

change the port

Port 22



to anything you like

then restart sshd damon
dont forget to add that port in iptables
also only allow certain ip to connect to the servier via iptables

dont allow it to every one. its a security risk
Avatar of CahitEy
CahitEy

ASKER

file is seems like the given below will i remove the ->  #  
then i will change it to another port and i will configure iptables before doing this is this right ?
#Port 22
#Protocol 2,1
Protocol 2
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::

# HostKey for protocol version 1
#HostKey /etc/ssh/ssh_host_key
# HostKeys for protocol version 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key

# Lifetime and size of ephemeral version 1 server key
#KeyRegenerationInterval 1h
#ServerKeyBits 768

Open in new window

Remove #  and change to anything like

Port 222

but change the iptables rules first. and restart iptables


-A RH-Firewall-1-INPUT -s xx.xx.xx.xxx -p tcp -m tcp --dport 222 -j ACCEPT


upper rules will allow only that ip to allow your ssh


Avatar of CahitEy

ASKER

ok then how could i restart ssh service to activate new port
ASKER CERTIFIED SOLUTION
Avatar of fosiul01
fosiul01
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial