e Learning

How to Change Default SSH Port Number in Centos7

If You Familiar with Linux Operating system you Should already Know that SSH (Secure Shell) is a secure network protocol which we can use to login to a Linux computer from remote location and access Linux command line interface. What we Normally do is use ssh client software like Putty or SecureCRT and login to remote computer by using IP address or Hostname.

By Default SSH uses TCP port 22 to establish the connection, but since everyone Knows what is the default port number is you may want to change ssh port from the default 22 to a different number for a security reason. Not a big deal we can Do that easily by editing sshd_conf file which is located at /etc/ssh Directory. So in this Tutorial i will Show you how to change SSH port in a Linux Server.

And also you can use this method in any Popular Linux distribution such as Ubuntu, Debian, Redhat and Fedora. For This Demonstration I Will Be Using Centos7.

First open /etc/ssh/sshd_config file using your favorite text editor, i’m going to use My Favorite Unix Text Editor vim.

vim /etc/ssh/sshd_config

Then find and uncomment the line which says Port 22 , Then change the port number to your New Port Number(I am Going to Use Port 22000) and save the Changes (Make sure to not to use common standard TCP port number to avoid collision between programmes)

change default ssh port number

Then Restart the ssh service. in CentOs7,RedHat7 and Fedora Desktop

/etc/init.d/sshd restart

And one More Thing, if You have IPTables Running you need to add a iptable rule to allow your new port number, so open /etc/sysconfig/iptables file with a text editor and add the following line (You Can Skip This Step If You have Stop Running iptable Firewall)

-A INPUT -p tcp -m state –state NEW -m tcp –dport 22000 -j ACCEPT

Now We Will Check the Connection. I’m going to use Putty as my SSH Client and My server IP Address is First Try to connect using Default port 22

Network Error Connection Refused

Putty Fatal Error : Network Error Connection Refused

Connection refused From port 22 as it should be , so at least now we know our Configuration has had an effect

Then let’s try using our new port number 22000, it should work

Login as Root

Yes, its Works, Great! Now You Can Enter Your Username and Password and access the Linux Shell.

Although default ssh port number does not mean your server is completely secure From Outside, But at least it adds some level of security to your Server.

Ok! Thats it For Today, hope you enjoyed and see you again With More Advanced Linux Tutorials.