Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm running a CENTOS web server with WHM and CSF firewall. I'm trying to change SSH from the default port. I've opened up the port in CSF and modified /etc/ssh/sshd_config uncommenting the port line and changing it to the port I want it to be on. I've then restarted SSH using WHM and command line and it restarts. However when it restarts it's still using the default port of 22. What am I doing wrong?

Settings from sshd_config file:

# Host *
#   ForwardAgent no
#   ForwardX11 no
#   RhostsRSAAuthentication no
#   RSAAuthentication yes
#   PasswordAuthentication yes
#   HostbasedAuthentication no
#   GSSAPIAuthentication no
#   GSSAPIDelegateCredentials no
#   GSSAPIKeyExchange no
#   GSSAPITrustDNS no
#   BatchMode no
#   CheckHostIP yes
#   AddressFamily any
#   ConnectTimeout 0
#   StrictHostKeyChecking ask
#   IdentityFile ~/.ssh/identity
#   IdentityFile ~/.ssh/id_rsa
#   IdentityFile ~/.ssh/id_dsa
Port 2222
#   Protocol 2,1
#   Cipher 3des
#   Ciphers aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc
#   MACs hmac-md5,hmac-sha1,,hmac-ripemd160
#   EscapeChar ~
#   Tunnel no
#   TunnelDevice any:any
#   PermitLocalCommand no
#   VisualHostKey no
Host *

Then here's the copy from my console so you can see what I ran:

root@vps1 [~]# cd /etc/ssh
root@vps1 [/etc/ssh]# vi ssh_config
root@vps1 [/etc/ssh]# /etc/init.d/sshd restart
Stopping sshd:                                             [  OK  ]
Starting sshd:                                             [  OK  ]
root@vps1 [/etc/ssh]#

I then ran netstat -tuplen to check the port it was running on:

tcp        0      0        *                   LISTEN      0          36862521   8315/sshd

Still running on port 22.

share|improve this question
What you're doing sounds right, so I suspect the devil is in the details. Could you show us what you've done, instead of telling us? Cutting-and-pasting bits of the relevant files and terminal sessions into your question is a good way to do that. – MadHatter Jul 8 '14 at 8:35
I only modified sshd_config, so I've copied the settings from there. As you can see I've only edited the port in there. I've copied the commands I ran in the terminal and as you can see it all went fine. But as you can see from netstat it's still on the wrong port. I've also tested it as I'm using PuTTY to make these changes. I'm still connected on port 22 and if I try the new port I can't connect. – Styphon Jul 8 '14 at 8:49
OK, thanks. That's weird. Could you perhaps do a service sshd stop, then /usr/sbin/sshd -d, and paste the debug output in here? Don't forget to do a service sshd start after you give the debugged one a CTRL-C, otherwise you may shut yourself out the box! – MadHatter Jul 8 '14 at 8:50
From what you just added, you edited ssh_config not sshd_config. You need to edit sshd_config – faker Jul 8 '14 at 8:50
Yaay faker, +1 from me. Styphon, your question serves as a perfect example of why show-not-tell is a good rule! You might want to take that lesson away with you for future questions! – MadHatter Jul 8 '14 at 8:55
up vote 7 down vote accepted

What you have in your question is not a sshd_config that is a ssh_config.
You need to edit sshd_config instead and restart sshd afterwards.

ssh_config is the client configuration and has no effect on daemon settings.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.