This topic contains 1 reply, has 2 voices, and was last updated by wangari wangari 2 years, 9 months ago.

  • Author
  • #1191
     Michael Dunn 

    Hi guys, I have a little question. I am an amateur CentOS Linux user and recently upgraded from CentOS 5.5 to CentOS 6. How do I change default sshd tcp port CentOS Linux version 5/6? Basically, how to change the SSH port?

  • #1192
    wangari wangari 

    How to change SSH Port

    The variety of ways to secure your server is innumerable. There are however some elementary steps and procedures that you can implement to cover your bases.

    When using a Linux server it is possible to change the SSH port from the default port (22).
    The following steps help you to do just that.

    Step 1. Reconfigure SSHD

    One of the simplest ways of changing the port is to SSH into the server as root.
    ssh root@hostname/IP
    NB: Replace hostname/IP with your server’s hostname or the main IP address of the same.

    So now that you are logged into the server as root, let’s begin editing the sshd_config file.

    Disclaimer: It is continually a great idea to backup any server file that you intend to make changes on.

    cp /etc/ssh/sshd_config /etc/ssh/sshd_config_backup
    Now we can modify the file.
    Using your preferred text editor, open /etc/ssh/sshd_config and identify the line that specifies the port. Unless your sshd_config file has been altered, the default setting is commented out with a #symbol as shown in the following example
    vim /etc/ssh/sshd_config

    # symbol informs the server to ignore everything that comes after it on the same line.
    That character will need to be removed and the number 22 changed to something else.
    NB: Ensure the port number you pick is not in use elsewhere. There is a list by Wikipedia of port numbers and their uses. You can use this to refer and pick a port number that is not in use or listed. For purposes of this examples we will apply port 2222 (a windows server port but not a default on Linux servers).
    Proceed to remove the # and change port number

    Save changes and close the sshd_config file.
    The new port also needs to be opened in the server’s firewall. This procedure explains firewall changes on a solitary VPS or dedicated server. In the instance of a hardware firewall in place, contact support for the necessary changes to be made.

    Step 2: Updating Firewall

    Here is a post on how to update the firewall.

    Step 3: Restart services

    APF and SSH must be restarted now to activate the changes made. Run the command ‘/etc/init.d/apf restart’ then ‘/etc/init.d/sshd restart
    service sshd restart

    service apf restart

    SSH will have restarted and listening on the specified port number.

    Note: Changing the SSH’s port number alters the way you run some commands that utilize SSH and need the new port number include scp and rsync.

You must be logged in to reply to this topic.


We're not around right now. But you can send us an email and we'll get back to you, asap.

TD Web Services



Log in with your credentials


Forgot your details?


Create Account