How To

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.

Cyber Defence

Recent Posts

Install PHP on Ubuntu 26.04: Apache, Nginx, and Multiple Versions

PHP 8.5 is included in Ubuntu 26.04's default repositories and is the recommended version for…

1 day ago

Upgrade to Ubuntu 26.04 from 25.10 and 24.04 LTS: Complete Guide

Ubuntu 26.04 LTS "Resolute Raccoon" arrived on April 23, 2026 with Linux kernel 7.0, GNOME 50,…

1 day ago

Install Kubernetes on Ubuntu 26.04 with kubeadm and containerd

Kubernetes is the standard platform for running containerized workloads across multiple servers with self-healing, rolling…

1 day ago

Install Ubuntu 26.04: Bootable USB, Partitioning, and First Steps

Ubuntu 26.04 LTS "Resolute Raccoon" was released on April 23, 2026 with Linux kernel 7.0, GNOME desktop, and standard security support until April 2031. A clean install gives you a known-good starting point on new hardware, when replacing another operating system, or when an upgrade path is not practical. This guide walks through how to install Ubuntu 26.04: downloading and verifying the ISO, writing a bootable USB drive, completing the installer, and doing the initial setup after the first boot. Before you start: You need a USB drive with at least 12 GB of free space. Back up any existing data on the target machine — the installer can erase the entire disk. Install Ubuntu 26.04: Download the ISO…

1 day ago

Change Timezone on Ubuntu: timedatectl and Desktop GUI Guide

The correct timezone affects more than the clock on your screen. It drives cron job scheduling, systemd timer execution, log file timestamps, database record timing, and SSL certificate validity checks. A mismatched timezone can cause scheduled jobs to fire at the wrong hour and make log timestamps impossible to match with real-world events. This guide shows how to change timezone on Ubuntu using the timedatectl command (the recommended approach for servers and remote machines) and through the graphical Date & Time settings on desktop systems. The steps apply to all current Ubuntu releases including 24.04 and 26.04. <strong>Prerequisite:</strong>&nbsp;Only&nbsp;the&nbsp;root&nbsp;user&nbsp;or&nbsp;a&nbsp;user&nbsp;with&nbsp;sudo&nbsp;access&nbsp;can&nbsp;change&nbsp;the&nbsp;system&nbsp;timezone. Check the Current Timezone Before You Change It Run timedatectl with no arguments to see the active timezone and clock status: bashtimedatectl Sample output: Local…

1 day ago

Install Atom on Ubuntu 18.04: GitHub’s Code Editor APT Setup

Atom is a free, open-source, cross-platform code editor developed by GitHub. Built on Electron, it uses…

2 days ago