The cart is empty

SSH (Secure Shell) stands as a critical component for secure remote connections to servers and devices. Ensuring our communication remains private and unaltered, it's crucial to properly configure and secure our SSH connections. In this article, we'll focus on two key methods of securing SSH: Public Key Authentication and port changing.

Public Key Authentication

Authentication via public key proves significantly more secure than traditional password-based methods. This approach utilizes a cryptographic key pair, public and private, to verify the user's identity. The public key resides on the server, while the private key remains with the client and is never transmitted.

To set up public key authentication, it's first necessary to generate a key pair using the ssh-keygen command. Once generated, the public key (usually id_rsa.pub) is transferred to the server and placed into the ~/.ssh/authorized_keys file of the user who will be logging in. This method greatly enhances security since physical access to the private key is required for login, making unauthorized access more difficult.

Port Changing

The standard port for SSH connections is 22. This fact is widely known, making it a frequent target for brute-force attacks and scanning. By changing the port to a less common and randomly selected number, we can significantly reduce the risk of automated attacks.

To change the port, the SSH daemon's configuration file needs adjustment, usually located in /etc/ssh/sshd_config. Here, you'll find the line #Port 22, which you'll change to, for example, Port 2222 (or any other less common port number). After making the change, it's necessary to restart the SSH service for the changes to take effect. It's also important not to forget to update firewall rules to allow connections on the new port.

These two methods, public key authentication and port changing, are fundamental steps you can take to secure your SSH connections. By combining these methods with other security practices such as using strong passwords, restricting access via firewall, and regularly updating software, you can significantly enhance the security of your servers and devices connected via SSH.