How to Change SSH Port in Ubuntu 24.04
SSH (Secure Shell) is a network protocol used to securely access and manage a server remotely. By default, SSH uses port 22. To enhance security, we can change the default SSH port to a different port number that is less commonly used. Changing the SSH port can help reduce the risk of brute force attacks or automatic port scanning.
Steps to Change SSH Port
Open the ssh.socket
configuration file:
1 | sudo nano /lib/systemd/system/ssh.socket |
For example, change the port from 22
to 2404
:
1 | ListenStream=2404 |
Then reload the daemon:
1 | sudo systemctl daemon-reload |
Open the sshd_config
configuration file:
1 | sudo nano /etc/ssh/sshd_config |
Change the line #Port 22
:
1 | Port 2404 |
Then restart the ssh
service:
1 | sudo systemctl restart ssh |
Check the service status to see if ssh
is using the new port:
1 | sudo systemctl status ssh |
If you found this article helpful and would like to support my work, consider making a donation through PayPal. Your support helps me continue creating useful content and tutorials. Thank you!
Donate via PayPal: https://paypal.me/musaamin