How To Generate SSH Key On Ubuntu Server 24.04?

Learn how you can generate SSH key pairs (public, and private key) for in Ubuntu, for setting up key authentication instead of passowrd authentication
6 min read
Intermediate
Generate SSH Key On Ubuntu Server 24.04

SSH on Linux distributions is commonly used to connect from other devices remotely to your Linux VPS server. To use the SSH service on your Linux device or your server, you need to create two SSH keys: one public and one private key.

First, you need to connect to your Ubuntu Server With SSH Using PuTTY application if you are using Windows. And if you are using other operating systems, you can connect to your server from their normal terminal.authencation

If you don’t have an Ubuntu VPS for yourself yet, you can buy an Ubuntu VPS and get starting in few minutes. then connect securely using the SSH keys you will generate following this article.

Generate SSH Key on Ubuntu 24.04

To use the SSH connection protocol with key authentication method instead of logging in with username and password every time, and generating SSH keys.

We will use the ssh-keygen command to generate keys. First, make sure you’ve installed OpenSSH correctly.

BASH
ssh -V

If it returns your OpenSSH version, it means you’ve installed it successfully and follow the steps below to create keys; otherwise, read the article for Installing OpenSSH on Ubuntu.

Create SSH Key Pair in Ubuntu

SSH keys have many types, including ed25519, which is a modern standard type, and an older and universally compatible type called RSA. You can see commands for creating both of them below:

ed25519 type:

BASH
ssh-keygen -t ed25519

RSA type:

BASH
ssh-keygen -t rsa -b 4096

Specify SSH Key Path in Ubuntu

After entering the command, it will ask you for a destination for saving the SSH keys. You can specify a destination for it, or you can leave it empty and press Enter to use the default destination, which is recommended.

specify destination for ssh key in linux terminal

Set Password on SSH Key in Ubuntu

Here in this step, you will be prompted to set a password for your keys. You can leave it empty and press Enter to continue. But it would be more secure if you set a password.

SSH key creation password requirement in linux terminal

Verify SSH Key in Ubuntu Server

After setting the password, you will see information about the generated key, like the fingerprints and random pattern generated for your key, and the location that your files are stored. You can navigate to that location to verify the file creation.

This is the default location where your keys are stored if you don’t change the destination path:

BASH
/home/username/.ssh

Open SSH Public Key in Ubuntu

To verify if your SSH keys are generated or not, you can open your SSH public key file and verify if its content is in the correct format or not.

Running this command, you can see the content of your public key file.

BASH
cat ~./.ssh/id_ed25519.pub
OUTPUT
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJa5yjA7UAGGiMYfbquPRMqY6+3lJZ/9NCxIHm45UOAb root@linux

Login to Linux Server with SSH Key

With the SSH key created, you can connect to other Linux servers from your Linux device, or if you are using a Linux server, you can accept incoming SSH connections with a key request.

For connecting to your Linux server, you need to copy your SSH key to the destination server, which you can do it manually by copying it to the ~/.ssh/authorized_keys file or you can use this command to automate this process.

BASH
ssh-copy-id username@server_ip

After running this command, you will be prompted to enter a password. You should enter the passphrase you set when generating your SSH key. This is only required for the first connection.

For future connections, you don’t need to use the command above; you can simply connect using the standard SSH command.

BASH
ssh username@server_ip

Common Issues of Creating SSH Key in Ubuntu

These are some issues you may encounter when creating an SSH key on your Ubuntu VPS server. Even small problems can lead to connection or authentication failures.

It is important to follow each step carefully. SSH connections are critical because they are very important for your system security.

ssh-keygen Not Recognized

This is one of the main and common issues you can face when you are using the ssh-keygen command; it says ssh-keygen is not recognized.

For fixing this issue, you need to install OpenSSH on your Ubuntu server to fix it. It is usually not installed on Linux distributions automatically; you need to install it manually.

SSH Folder Permissions in Ubuntu

Sometimes, SSH key creation or usage can fail due to incorrect permissions on the .ssh directory. You need to set the correct permissions on your Linux server. SSH requires strict permissions for security reasons, and if your permissions are open to everyone, it may be ignored.

It’s better to have permissions like:

FilenamePermissionCommand
.ssh DirectoryFull access to root usersudo chmod 700 ~/.ssh
Private KeyRead and Write access to root usersudo chmod 600 ~/.ssh/id_ed25519
Public KeyReadable for all users and modifiable by rootsudo chmod 744 ~/.ssh/id_ed25519.pub

Overwrite Existing SSH Key in Ubuntu

When generating a new SSH key, you will be warned whether you want to overwrite the existing key; this action would cause problems if the previous key was already being used. To avoid this issue, you can back up your SSH keys, or you can take backup of your Linux VPS.

SSH key Firewall Problems in Ubuntu

You may also encounter silent connection issues, where everything is configured correctly, but you still cannot connect. This can happen if your Linux server firewall is blocking SSH traffic, especially on port 22 (and in some cases other ports if they were changed from the default).

You can fix this problem by opening the specified port for SSH on Linux firewall.

Conclusion

SSH is the key connection type to Linux servers, and if you want to make it more secure, you can use SSH keys to avoid using a username and password on every login. We covered how you can create it on your Ubuntu server in this article and explained the common issues you may face.

If you want to connect with SSH key pairs from a Windows device, you need to create SSH keys on Windows, too.

Share:

Was this article helpful?

Your feedback helps us improve our technical guides.

Related Posts

You May Also Like

Explore more tutorials, guides, or documentation, from VPSMakers.

Learn how to extract regular, multi-part, and password-protected RAR files on Ubuntu VPS using command-line and graphical tools.
Richard Mourar
November 21, 2026
Learn how to resize Windows partitions by shrinking and extending volumes using Disk Management and DiskPart utility to manage disk space.
Jacob Rafet
November 20, 2026
Open ports on Windows 10 and Windows Server using Windows Firewall or PowerShell. Allow TCP and UDP connections and verify firewall rules.
Robert Smith
November 19, 2026
Block ports in Windows using Firewall or PowerShell by creating inbound or outbound rules for specific ports and protocols.
Robert Smith
November 17, 2026