Skip to content

Instantly share code, notes, and snippets.

@rothkj1022
Last active April 10, 2019 17:28
Show Gist options
  • Save rothkj1022/f03adfc51366e523f2e3bf8620a1e0ff to your computer and use it in GitHub Desktop.
Save rothkj1022/f03adfc51366e523f2e3bf8620a1e0ff to your computer and use it in GitHub Desktop.

Change SSH Port on CentOS 7

Back up sshd_config

$ sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak

Edit config to change port and disallow password auth

$ sudo nano /etc/ssh/sshd_config

Find the following line:

# Port 22

and change to something like:

Port 2244

Find the folling line:

#PermitRootLogin yes

and change to:

PermitRootLogin no

Exit and save.

Reload sshd and DO NOT EXIT YOUR SESSION

$ systemctl reload sshd

Open a new terminal window. In the new window, we need to begin a new connection to our server, using the new port number

# ssh user@yourserver.domain.com -p 2244

If you are able to connect, you may close your original terminal session. If not, recheck your sshd_config.

If you don't want to type in your port number in the future for connections to this server, you may modify your .ssh/config file to add something like the following:

Host yourserver.domain.com
  Port 2244
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment