Cybersecurity Updates & Tools

SSH Key Authentication: Secure Ubuntu Server Access

SSH Key Authentication is one of the most effective ways to secure remote Linux server access. Instead of relying on traditional passwords, this method uses a cryptographic key pair to verify identities, making unauthorized access significantly more difficult. If you manage Ubuntu servers, setting up SSH keys should be a top security priority.

In this guide, you’ll learn how to create SSH keys, configure passwordless login, and strengthen your Ubuntu server security.

Why Use SSH Key Authentication?

Remote server management often relies on Secure Shell (SSH), a protocol designed to establish encrypted connections between systems. While password-based logins are common, they are more vulnerable to brute-force attacks and credential theft.

With SSH Key Authentication, users authenticate using a private key stored on their device and a public key placed on the server. This approach offers several advantages:

  • Stronger security than passwords
  • Faster logins without repeated password entry
  • Better protection against automated attacks
  • Simplified management across multiple servers

For administrators handling cloud instances, VPS environments, or enterprise infrastructure, SSH keys have become the recommended authentication standard.

Generate SSH Key Authentication Credentials

Before configuring a remote server, check whether an SSH key pair already exists on your Ubuntu machine:

ls -l ~/.ssh/id_*.pub

If no public key is found, create a new RSA key pair:

ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

Ubuntu will ask where to save the key. Press Enter to accept the default location.

You can also add a passphrase for additional protection. While optional, a passphrase provides another layer of security if your private key is ever exposed.

Once completed, verify the generated files:

ls ~/.ssh/id_*

You should see both a private key and a public key.

Configure SSH Key Authentication on a Remote Server

After generating the keys, copy the public key to the target Ubuntu server.

The easiest method uses the built-in utility:

ssh-copy-id username@server_ip

Enter the remote account password when prompted. The tool automatically places the public key in the server’s authorized keys file.

If the utility is unavailable, manually transfer the key:

cat ~/.ssh/id_rsa.pub | ssh username@server_ip "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys"

Once the key is installed, test the connection:

ssh username@server_ip

If everything is configured correctly, you’ll log in without entering the account password.

Improve Security by Disabling Password Logins

To maximize the benefits of SSH Key Authentication, disable password-based access after verifying that key-based login works.

Open the SSH daemon configuration file:

sudo nano /etc/ssh/sshd_config

Update the following settings:

PasswordAuthentication noChallengeResponseAuthentication noUsePAM no

Save the file and restart the SSH service:

sudo systemctl restart ssh

This change blocks password-based logins and reduces exposure to automated attack attempts.

Best Practices for SSH Security

While SSH keys provide excellent protection, consider these additional security measures:

  • Use strong passphrases for private keys.
  • Restrict SSH access with firewall rules.
  • Regularly rotate keys for critical systems.
  • Change the default SSH port if appropriate.
  • Monitor authentication logs for suspicious activity.

Combining these practices with SSH key-based access creates a significantly stronger security posture.

Conclusion

Implementing SSH Key Authentication on Ubuntu is a simple but powerful step toward securing remote server access. By replacing passwords with cryptographic keys, administrators gain stronger protection, improved convenience, and reduced risk from brute-force attacks. Whether you’re managing a single VPS or an entire infrastructure, SSH Key Authentication should be part of every server hardening strategy.