SSH key authentication is far more secure than passwords. This guide covers generating an Ed25519 key pair and deploying it on Ubuntu 24.04 LTS.

Tested and valid on:

  • Ubuntu 24.04 LTS

Prerequisites

  • Ubuntu 24.04 LTS server with SSH running
  • A user account on the server
  • An SSH client on your local machine (Linux/macOS/Windows)

Step 1 – Generate an SSH Key Pair (on your local machine)

Ed25519 keys are recommended for their speed and security:

ssh-keygen -t ed25519 -C "your_email@example.com"

Accept the default path and set an optional passphrase.

Step 2 – Copy the Public Key to the Server

Use ssh-copy-id:

ssh-copy-id username@your_server_ip

Or manually append it:

cat ~/.ssh/id_ed25519.pub | ssh username@your_server_ip "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"

Step 3 – Set Correct Permissions on the Server

SSH requires strict permissions:

chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys

Step 4 – Test Key Authentication

Log in with your key:

ssh username@your_server_ip

Step 5 – Disable Password Authentication

Open the SSH config:

sudo nano /etc/ssh/sshd_config

Set:

PasswordAuthentication no
PubkeyAuthentication yes

Reload SSH:

sudo systemctl reload ssh

Step 6 – Add the Key to ssh-agent (optional)

To avoid entering the passphrase every session:

eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519

Conclusion

Your Ubuntu 24.04 LTS server now requires SSH key authentication, eliminating password brute-force risk. Store your private key securely and back it up.