Knowledgebase

How to Change the SSH Port Print

  • 0

Introduction

Port 22 is used to establish an SSH connection by default. You can strengthen the server security by modifying the SSH port to prevent brute force attacks.

This article introduces the steps on how to change the SSH port.

1 Log in to the server.

2 Edit the SSH configuration file.

3 Save the configuration file and exit.

4 Restart the SSH service.

5 Log in to the server with the new port.

 

1 Log in to the server

For how to log in to the Linux server, please refer to How to SSH to a Linux Server. If the system is Ubuntu OS, please switch to root user with the command "sudo-i".

# sudo -i

2 Edit the SSH configuration file

The SSH configuration file is sshd_config. You can use "vi" to edit the configuration.

First, enter the command below 

# vi /etc/ssh/sshd_config

Next,  type "/Port" to search for the <port command> and uncomment the "#". Then, change the port to a larger number such as 15678.

Please note that the port number must be between 1024 and 65536.

3 Save the configuration file and exit

Save the configuration file and exit with the command ":wq".

4 Restart the SSH service

Restart the SSH service for the configuration to take effect.

# service sshd restart

5 Log in to the server with the new port

After you change the SSH port, the session breaks. You need to log back in to the server using the new port.

Was this answer helpful?
Back