Role of SSH Public Keys on Ubuntu Servers

Secure Shell (SSH) is the standard protocol used to securely access and manage remote Ubuntu Linux servers. This article explains the specific role that the public key plays in SSH key-based authentication, detailing how it acts as a secure digital lock on the server that can only be unlocked by its corresponding private key.

The Concept of Asymmetric Cryptography

SSH key-based authentication relies on asymmetric cryptography, a system that uses a pair of mathematically linked keys: a public key and a private key.

The Role of the Public Key: The Digital Lock

In SSH authentication, the public key acts as a digital lock. Its primary role is to encrypt data in a way that can only be decrypted by the matching private key.

On an Ubuntu server, your public key is saved in a specific file within the home directory of the user you want to log in as: ~/.ssh/authorized_keys.

When you attempt to connect to the Ubuntu server via SSH, the authentication process unfolds as follows:

  1. The Challenge: The Ubuntu server looks in the authorized_keys file for a public key associated with your username.
  2. Encryption: If it finds the public key, the server generates a random challenge message and encrypts it using that public key.
  3. The Response: The server sends this encrypted message to your local machine. Because only the matching private key can decrypt this message, your local SSH client uses your private key to decrypt the challenge, signs it, and sends it back to the server.
  4. Verification: The server verifies the response. If the response is correct, the server grants you access.

Why the Public Key Enhances Security on Ubuntu

Using a public key for SSH authentication on Ubuntu offers major security advantages over traditional password-based logins: