Best Practices to configure SSH Credentials

Mamta Meshram
Tera Contributor

Hello,

 

I am looking for best practice to configure SSH credentials.

 

Br,

1 REPLY 1

Amit Gujarathi
Giga Sage

Hi @Mamta Meshram ,
I trust you are doing great.

Best Practices for Configuring SSH Credentials:

  1. Use SSH Key Authentication: Instead of relying on password-based authentication, use SSH key pairs. This involves generating a public and private key pair. The public key is placed on the server, and the private key remains with the client.

 

ssh-keygen -t rsa -b 4096

 

Protect Your Private Key: Ensure that your private key is kept secure. Set restrictive permissions to prevent unauthorized access.

 

chmod 600 ~/.ssh/id_rsa

 

Disable Root Login: Never allow direct SSH access to the root user. Instead, log in as a standard user and elevate privileges as needed.

In the SSH configuration file (/etc/ssh/sshd_config), set:

 

PermitRootLogin no

 

  1. Use Strong Passphrases: When generating your SSH key pair, always use a strong passphrase. This adds an additional layer of security.

  2. Limit User Access: Only allow necessary users to SSH into the server. You can specify allowed users with the AllowUsers directive in the SSH configuration file.

  3. Change Default SSH Port: While security through obscurity is not a robust strategy on its own, changing the default SSH port (22) can reduce the risk of automated attacks.

    In the SSH configuration file, set:

 

Port [desired_port_number]

 

  1. se Fail2Ban: Install and configure Fail2Ban to monitor and block repeated failed login attempts, reducing the risk of brute-force attacks.

  2. Regularly Update SSH: Ensure that the SSH server is regularly updated to benefit from security patches and improvements.

 

sudo apt update && sudo apt upgrade

 

Disable Empty Passwords: Ensure that users cannot set empty passwords.

In the SSH configuration file, set:

 

PermitEmptyPasswords no

 

Monitor SSH Logs: Regularly monitor SSH logs (/var/log/auth.log on many systems) to keep an eye on login attempts and other SSH-related activities.


Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi