Website Vidya
SecurityStep-by-Step Guide

How to Set Up SSH Keys on Ubuntu 24.04

Learn how to set up SSH keys on Ubuntu 24.04 LTS using Ed25519 and RSA, copy public keys with ssh-copy-id, and disable password login securely.

RR
Rajesh RayLead Systems Educator
Published:
6 min read
PDF Cheat Sheet
How to Set Up SSH Keys on Ubuntu 24.04
AI Executive SummaryWebsiteVidya AI

6 min read

Learn how to set up SSH keys on Ubuntu 24.04 LTS using Ed25519 and RSA, copy public keys with ssh-copy-id, and disable password login securely.

Key Highlights
  • Prerequisites and Supported Releases
  • Step 1: Choosing Between Ed25519 and RSA Key Algorithms
  • Step 2: Generating a New Ed25519 SSH Key Pair on Your Client
Grounded in full engineering runbookWebsiteVidya AI Engine

Securing remote server infrastructure begins with replacing vulnerable password authentication with robust public-key cryptography. When you set up ssh keys on ubuntu 24.04, you eliminate the risk of automated credential brute-forcing, dictionary attacks, and credential stuffing on public-facing SSH ports.

Public-key authentication relies on an asymmetric cryptographic key pair: a private key that remains strictly confidential on your local client machine, and a public key that you install on the remote server's ~/.ssh/authorized_keys file. This guide covers modern Ed25519 algorithm generation, transferring keys via ssh-copy-id, client-side configuration profiling, and production OpenSSH daemon hardening.

Prerequisites and Supported Releases

This guide is thoroughly verified on Ubuntu 24.04 LTS (Noble Numbat) & Ubuntu 22.04 LTS. The instructions apply cleanly to cloud instances (AWS EC2, Google Compute Engine, DigitalOcean, Hetzner), bare-metal servers, and local virtual machines.

Advertisement

Before proceeding, ensure you have the following requirements satisfied:

  • A client workstation (Ubuntu, macOS, Linux, or Windows with OpenSSH client).
  • A remote Ubuntu 24.04 LTS server with OpenSSH server running and port 22 open.
  • A non-root user account on the server with sudo administrative privileges.
  • Initial password-based SSH access to the remote server.

Step 1: Choosing Between Ed25519 and RSA Key Algorithms

Before generating an SSH key pair, you must select an asymmetric cryptographic algorithm. Modern security engineering strongly favors the Ed25519 algorithm (elliptic curve cryptography) over traditional RSA.

Ed25519 offers superior mathematical security, faster signature verification, resistance to side-channel timing attacks, and compact 68-character keys compared to bulky 4096-bit RSA keys.

AlgorithmKey LengthSecurity LevelRecommendation
Ed25519256 bitsModern standard (~128-bit security)Strongly Recommended (Default)
RSA4096 bitsLegacy standard (~128-bit security)Acceptable for legacy system compatibility
RSA2048 bitsBorderline legacyNot recommended for new deployments
DSA / ECDSAVariousFlawed / weak curvesDeprecated by OpenSSH

Step 2: Generating a New Ed25519 SSH Key Pair on Your Client

Adding a passphrase encrypts the private key file on your local disk using AES-256. Even if an attacker gains physical or remote access to your laptop, they cannot authenticate to your servers without the passphrase.

Advertisement
# Generate a secure Ed25519 SSH key pair on your local client
ssh-keygen -t ed25519 -C "[email protected]"

# Interactive prompt:
# Generating public/private ed25519 key pair.
# Enter file in which to save the key (/home/user/.ssh/id_ed25519): [Press Enter]
# Enter passphrase (empty for no passphrase): [Enter a strong passphrase]
# Enter same passphrase again: [Repeat passphrase]

Step 3: Copying the Public Key to the Remote Ubuntu Server

Once the key pair is generated, you must copy your public key (id_ed25519.pub) to the remote server. Never transfer or share your private key.

The fastest and most reliable method is using the native ssh-copy-id utility.

# Copy your public key to the remote server
ssh-copy-id -i ~/.ssh/id_ed25519.pub user@server_ip_address

# Output sample:
# /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/user/.ssh/id_ed25519.pub"
# /usr/bin/ssh-copy-id: INFO: attempting to log in with the given keys...
# user@server_ip_address's password: 
# Number of key(s) added: 1
# Now try logging into the machine, with: "ssh 'user@server_ip_address'"

Alternative: Manually Installing the Public Key via SSH Pipe

If ssh-copy-id is unavailable on your client operating system, append your public key using a remote shell pipe:

# Manually transmit and append the public key
cat ~/.ssh/id_ed25519.pub | ssh user@server_ip_address "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"

Step 4: Authenticating to the Remote Server Using Your Key

Once authenticated, you will arrive at the remote shell prompt without being prompted for your remote account's Linux password.

Advertisement
# Log in to the remote server using SSH
ssh user@server_ip_address

# If prompted:
# Enter passphrase for key '/home/user/.ssh/id_ed25519': [Enter passphrase]

Step 5: Hardening OpenSSH Server by Disabling Password Authentication

Generating SSH keys improves convenience, but your server remains vulnerable to brute-force attacks until you explicitly disable password-based logins.

On your remote Ubuntu 24.04 server, edit the OpenSSH daemon configuration file. Note that Ubuntu 24.04 uses the modular drop-in configuration directory /etc/ssh/sshd_config.d/.

# Create a dedicated hardening override configuration file
sudo nano /etc/ssh/sshd_config.d/50-security-hardening.conf

Applying Mandatory Security Directives

Add the following hardening parameters into the configuration file:

# Disable password authentication completely
PasswordAuthentication no
KbdInteractiveAuthentication no

# Disable root user login over SSH
PermitRootLogin no

# Enforce public key authentication
PubkeyAuthentication yes

# Disallow empty passwords
PermitEmptyPasswords no

Validating Configuration Syntax and Reloading sshd

Always test the OpenSSH daemon configuration syntax with sshd -t before reloading the service. A syntax error could lock you out of remote access.

# Test configuration syntax
sudo sshd -t

# If no errors are returned, reload the SSH service
sudo systemctl reload ssh

Step 6: Streamlining Connections with Client-Side ~/.ssh/config

Now, you can connect to your remote production server by simply typing ssh production.

Using a client-side configuration file also prevents configuration drift across engineering teams. You can enforce modern cipher suites, configure JumpHost proxy forwarding (ProxyJump [email protected]) to access private VPC subnets, and establish automated connection persistence over unstable cellular or home networks.

Host production
    HostName 203.0.113.50
    User ubuntu
    Port 22
    IdentityFile ~/.ssh/id_ed25519
    ServerAliveInterval 60
    ServerAliveCountMax 3

Host staging
    HostName 203.0.113.51
    User developer
    Port 2222
    IdentityFile ~/.ssh/id_ed25519

Troubleshooting and Common Errors

When configuring Ubuntu servers, unexpected permission errors, network timeouts, or lock contention can occur. Review these common issues and verified resolutions:

Permission denied (publickey).

Cause: File permissions on ~/.ssh or ~/.ssh/authorized_keys are too open, triggering strict OpenSSH security rejections.

Resolution: Ensure directory permissions are 700 and file permissions are 600: chmod 700 ~/.ssh && chmod 600 ~/.ssh/authorized_keys.

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

ssh-copy-id: command not found on Windows.

Cause: Windows OpenSSH client does not include the POSIX ssh-copy-id shell script.

Resolution: Use PowerShell to append the public key content into the remote authorized_keys file via SSH pipe.

type $env:USERPROFILE\.ssh\id_ed25519.pub | ssh user@server "cat >> .ssh/authorized_keys"

SSH key prompt asks for passphrase on every connection.

Cause: The local ssh-agent service is not caching the unlocked private key identity.

Resolution: Start ssh-agent and add your key: eval $(ssh-agent -s) && ssh-add ~/.ssh/id_ed25519.

ssh-add ~/.ssh/id_ed25519

Security Best Practices and Hardening

Never share or commit private keys (id_ed25519 or id_rsa) into Git repositories.

Store production server backup keys in encrypted password managers, and always enforce passphrases on developer workstations.

Periodically audit ~/.ssh/authorized_keys across all production instances and decommission stale keys belonging to departed engineers or decommissioned CI runners.

Disable SSH Agent Forwarding (ForwardAgent no) by default to prevent rogue servers from hijacking active local credentials.

Deepen your Linux system administration skills with our related production-tested guides:

Authoritative References and Official Documentation

Frequently Asked Questions

Quick answers to common questions and configurations

4 FAQs
Ed25519 uses high-speed elliptic curve cryptography (Curve25519). It provides equal or superior cryptographic strength to a 4096-bit RSA key while being significantly shorter, faster to sign, and immune to side-channel timing vulnerabilities.
If you lose your private key or misconfigure sshd, access your server using your cloud hosting provider's web-based VNC/KVM recovery console. Log in via console, inspect /etc/ssh/sshd_config.d/, and fix the configuration.
No. Each developer, administrator, or deployment automation system should generate their own distinct key pair. Multiple public keys can be added to the server's authorized_keys file on separate lines.
Open ~/.ssh/authorized_keys on the server in a text editor, locate the corresponding public key line (identified by its comment at the end), delete that line, and save the file.
RR
Written byVerified Author

Rajesh Ray

I’m Rajesh Rai, a full-stack developer, Linux administrator, and technology enthusiast passionate about making complex technology easier to understand and use.

SPAM-FREE MODERATED DISCOURSE

Join the Conversation & Perspective

Have thoughts, counterpoints, or reflections on this story? Engage directly with fellow readers and editorial contributors.

AT
MP
JV
+2

No comments on this guide yet. Be the first to share your thoughts or ask a question!

Recommended Reading10 Guides

Related Technical Guides

Tested runbooks, server administration walkthroughs, and troubleshooting guides

Featured Infrastructure PartnerUp to 75% OFF + 3 Months Free

Supercharge Your Linux & Cloud Workloads with Hostinger

Deploy high-speed NVMe KVM VPS, Docker containers, and LiteSpeed-accelerated WordPress servers in under 60 seconds with full root access, dedicated IPv4, and 24/7 technical support.

Pure NVMe SSD StorageFull Root Access & SSHFree Domain & Unlimited SSL99.9% Uptime SLA
Plans from$2.99/mo
Claim Hostinger DealAffiliate link • Special discount applied at checkout