OpenSSH Hardened Server Configuration and how to hardening ?

Before implementing any SSH hardening tips, it is important to thoroughly review each one and evaluate if they are necessary for your specific use case. Not all tips may be applicable or compatible with each other. Blindly following all tips may not be the best approach to hardening your SSH server.

SSH server hardening is particularly important because SSH (Secure Shell) is a critical component of secure system administration. SSH is a protocol that allows users to securely log into a remote system and perform administrative tasks. Hardening the SSH server helps to ensure that remote access to the system is secure and that only authorized users can access the system.

Here are some reasons why SSH server hardening is important:

Overall, SSH server hardening is critical for securing remote access to systems and protecting sensitive data and system configurations. By hardening the SSH server, organizations can help to ensure that remote access to their systems is secure and that only authorized users can access the system.

The above lines are a configuration file for an OpenSSH server and set various settings for the server's operation. Here is a brief explanation of each line:

SSH configuration file location  `/etc/ssh/sshd_config`

An example of how to harden a Linux server through SSH (Please note its not a complete example )

1. Use SSH keys for authentication:

SSH keys are more secure than passwords since they are harder to brute-force. To use SSH keys for authentication, first, generate a new SSH key pair on your local machine using the `ssh-keygen` command:

   ```

   ssh-keygen -t rsa

   ```

This will generate a public and private key pair in the `~/.ssh` directory. Then, copy the public key to the server by using the `ssh-copy-id` command:

   ```

   ssh-copy-id username@server_ip

   ```

 This will add the public key to the authorized keys list on the server, allowing you to log in using the private key without a password.

2. Disable root login:

To disable root login, edit the SSH configuration file `/etc/ssh/sshd_config` and set the `PermitRootLogin` parameter to `no`:

   ```

   PermitRootLogin no

   ```

This will prevent anyone from logging in as the root user over SSH, which can help to prevent unauthorized access and protect against brute-force attacks.

3. Use strong authentication methods:

You can use additional authentication methods like two-factor authentication (2FA) or multifactor authentication (MFA) to add an extra layer of security to your SSH logins. There are several methods for implementing 2FA/MFA, including using Google Authenticator or Duo Security.

4. Change the default SSH port:

By default, SSH listens on port 22, which can make your server vulnerable to automated attacks. Changing the SSH port to a non-standard port can make it harder for attackers to find your SSH service. To change the default SSH port, edit the SSH configuration file `/etc/ssh/sshd_config` and set the `Port` parameter to a non-standard port (e.g., 2200):

   ```

   Port 2200

   ```

After changing the SSH port, you will need to specify the new port when connecting to the server over SSH:

   ```

   ssh -p 2200 username@server_ip

   ```

Be sure to open the new port in your server's firewall configuration.

5. Use SSH protocol version 2:

SSH protocol version 1 is deprecated and insecure, so it's important to ensure that your server is using SSH protocol version 2. To do this, edit the SSH configuration file `/etc/ssh/sshd_config` and set the `Protocol` parameter to `2`:

   ```

   Protocol 2

   ```

6. Limit SSH access to specific IP addresses:

To restrict SSH access to specific IP addresses, edit the SSH configuration file `/etc/ssh/sshd_config` and set the `ListenAddress` parameter to the IP address(es) you want to allow:

   ```

   ListenAddress 192.168.1.100

   ```

This will only allow SSH connections from the specified IP address(es).

By following these steps, you can harden your Linux server using SSH to help protect against unauthorized access and brute-force attacks.