User Tools

Site Tools


security:misc:how-can-i-change-my-ssh-port

Changing default SSH port in OpenSSH

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

  1. SSH into your server as the root user.
    • ssh root@<ip address> -p 2200
  2. 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
  3. Line #13 shows the current configured port number. (ie. Port 2200) Meaning, SSH is currently using 2200.
  4. Change the numerical digits from 2200 to your desired port number, for this example we will be using 2222.
  5. 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].
  6. You'll again be prompted, "File Name to Write: /etc/ssh/sshd_config" , simply press [Enter] at this time.
  7. 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  ]
  8. 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.

security/misc/how-can-i-change-my-ssh-port.txt · Last modified: 2015/01/13 03:48 by Jonathan W.