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.

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.
- 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
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.
SSH key authentication provides a cryptographic security upgrade over traditional passwords, protecting remote servers against automated brute-force attacks. This comprehensive tutorial demonstrates how to set up SSH keys on Ubuntu 24.04 LTS, generate secure Ed25519 key pairs, install public keys on remote servers with ssh-copy-id, and harden OpenSSH by disabling password authentication.
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.
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.
| Algorithm | Key Length | Security Level | Recommendation |
|---|---|---|---|
| Ed25519 | 256 bits | Modern standard (~128-bit security) | Strongly Recommended (Default) |
| RSA | 4096 bits | Legacy standard (~128-bit security) | Acceptable for legacy system compatibility |
| RSA | 2048 bits | Borderline legacy | Not recommended for new deployments |
| DSA / ECDSA | Various | Flawed / weak curves | Deprecated 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.
# 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.
# 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
Do NOT close your existing terminal session after reloading ssh. Open a brand-new terminal window and verify that you can successfully connect with your SSH key before terminating your active session.
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.
Related Ubuntu Tutorials and Documentation
Deepen your Linux system administration skills with our related production-tested guides:
- How to Enable SSH on Ubuntu — Install and configure OpenSSH server daemon on your Ubuntu system.
- How to Create a Sudo User on Ubuntu — Provision dedicated administrative user accounts for SSH key assignment.
- How to Set Up a Firewall with UFW on Ubuntu — Protect your SSH service with firewall rate limiting rules.
Authoritative References and Official Documentation

The Linux Command Line, 2nd Edition: A Complete Introduction
Frequently Asked Questions
Quick answers to common questions and configurations
/etc/ssh/sshd_config.d/, and fix the configuration.authorized_keys file on separate lines.~/.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.Editorial Disclosure: Website Vidya is supported by our readers. When you purchase hosting, tools, or software through our verified partner links, we may earn an affiliate commission at no extra cost to you. We only recommend solutions we trust and rigorously verify.
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.
Most Read Guides
TrendingUbuntu Server Not Booting? 10 Simple Steps to Fix It Fast
How to Create a 3D Button in HTML and CSS: Easy Steps
How to Install Python and Pip on Ubuntu 24.04 LTS
How to Install Nginx on Ubuntu 24.04
How to Install Python on Ubuntu 24.04 LTS
Related Technical Guides
Tested runbooks, server administration walkthroughs, and troubleshooting guides
Join the Conversation & Perspective
Have thoughts, counterpoints, or reflections on this story? Engage directly with fellow readers and editorial contributors.
No comments on this guide yet. Be the first to share your thoughts or ask a question!