To Change the SSH Port for Linux Server
- Connect to your server via SSH
- Switch to the root user
- Run the following command:
- Locate the following line:
# What ports, IPs and protocols we listen for
# Port 22
- Remove # and change 22 to your desired port number.
- Restart the sshd service by running the following command:
service sshd restart
After you’ve made the above changes, restart the SSH daemon to reflect changes and issue netstat or ss command to confirm that SSH service listens on the new TCP port.
systemctl restart ssh netstat -tlpn| grep ssh ss -tlpn| grep ssh