KNOWNHOST KNOWLEDGE BASE

Hosting Question? Find the Solution - Browse our Guides, Articles, and How-To's

How can I change my SSH port?

Category: Technical Support
Tags: # # #

The default SSH port on all Operating Systems is port 22. For security measures, KnownHost’s servers are configured to use port 2200.

Changing your SSH port

The server’s SSH configuration file is located here: /etc/ssh/sshd_config

  • SSH into your server as the root user.
    • ssh root@<ip address> -p 2200
  • Open the configuration file with your favorite text editor. (nano -c in this example. The -c flag shows the line number.)
    • nano -c /etc/ssh/sshd_config
  • Line #13 shows the current configured port number. (ie. Port 2200) Meaning, SSH is currently using 2200.
  • Change the numerical digits from 2200 to your desired port number, for this example we will be using 2222.
  • After changing to your desire port, Press [CTRL] + X to save the changes. You’ll be prompted, “Save modified buffer (ANSWERING “No” WILL DESTROY CHANGES) ?” Press Y and then [Enter].
  • You’ll again be prompted, “File Name to Write: /etc/ssh/sshd_config” , simply press [Enter] at this time.
  • Restart the SSH daemon:
    • /etc/init.d/sshd restart
    • You should see that it was stopped and started successfully:
  Stopping sshd:              [  OK  ]
  Starting sshd:              [  OK  ]
  • For good measure, let’s confirm the changes were made and it’s running properly.
  # netstat -tulpn |grep sshd
  tcp     0     0  0.0.0.0:2222     0.0.0.0:*   LISTEN   5672/sshd 
  tcp     0     0       :::2222          :::*   LISTEN   5672/sshd
  • :2222 shows that it’s listening properly on 2222 now, rather than 2200.

Now when connecting to your server use the newly configured port number.