How to Change SSH Port in CentOS



cd /etc/ssh
vi sshd.config

Lets see the ssh port that linux is running

service sshd status
-------------------------------------------------------------------
Nov 29 15:19:09 centos-vps-1 sshd[840]: Server listening on :: port 22.
Nov 29 15:19:09 centos-vps-1 systemd[1]: Started OpenSSH server daemon.
Nov 29 15:19:12 centos-vps-1 sshd[884]: Did not receive identification string from 209.1...070
Nov 29 15:23:48 centos-vps-1 systemd[1]: Stopped OpenSSH server daemon.
Nov 29 15:24:05 centos-vps-1 systemd[1]: Starting OpenSSH server daemon...
Nov 29 15:24:05 centos-vps-1 sshd[390]: Server listening on 0.0.0.0 port 22.

Default port is 22 and assume you want to change to 2222

1. cd /etc/ssh
2. vi sshd.config
3. find #port 22 
4. uncomment the #port 22 and update with port 2222
5. now quit the editor with :wq!