Generating an SSH Key Pair in Ubuntu 24.04/24.10

Looking to make your remote connections more secure in Ubuntu 24.04/24.10? A great way to start is by generating an SSH key pair. An SSH key pair consists of two parts: a private key, which stays on your local machine, and a public key, which you share with the remote server. With this setup, you can connect to servers securely without needing to type in your password every time. Let’s look at how you can set this up and find out some new tips along the way.

Why SSH Keys?

SSH (Secure Shell) is a protocol designed to help you securely access remote servers over an unsecured network. It’s widely used by developers, system admins, and anyone managing servers. Using SSH keys instead of passwords takes security up a notch because it’s much harder to brute-force or guess a key than a password. Plus, it makes logging in faster and easier—especially for automation tasks or when dealing with multiple servers.

If you’ve used SSH keys before, you’ll find the process for Ubuntu 24.04/24.10 similar to previous versions. If not, don’t worry—this guide will walk you through it step by step.

Step 1 – Check for Existing SSH Keys

Before creating a new SSH key pair, it’s a good idea to check if you already have one:

1. Open a terminal.

2. Navigate to your SSH directory:

3. List the contents of the directory:

If you see files like id_rsa and id_rsa.pub, congrats! You already have an SSH key pair. If not, or if you want to generate a new one, let’s move to the next step.

Step 2 – Generate a New SSH Key

Generating a new SSH key pair in Ubuntu 24.04/24.10 is straightforward with the ssh-keygen tool. Here’s the command:

Let’s break this down:

  • -t ed25519 – Specifies the type of key. Ed25519 is faster and more secure than the older RSA algorithm.
  • -C “your_email@example.com” – Adds a comment to the key, like your email address, so you can identify it easily later.

If you need compatibility with older systems, you can use RSA:

You’ll be prompted to:

1. Choose a file location for the key. Press Enter to save it to the default location (~/.ssh/id_ed25519).

2. Set a passphrase for the private key. A strong passphrase adds an extra layer of security. You can skip this step by pressing Enter, but a passphrase is highly recommended.

Step 3 – Add Your Public Key to a Server

Once you have your SSH key pair, the next step is to share your public key with the server you want to connect to. Here’s how:

Option 1 (Manual Method)

1. Display the contents of your public key:

2. Copy the entire output.

3. Log in to your server:

4. Create the .ssh directory on the server (if it doesn’t exist):

5. Open the authorized_keys file on the server and paste your public key:

Option 2 (Use ssh-copy-id Command)

Save time by using the ssh-copy-id command, which handles everything for you:

You’ll be prompted for your password. After it’s done, you can use your key for authentication.

Step 4 – Test Your Key-Based Authentication

1. From your local machine, run:

2. If configured correctly, you’ll connect without entering your password. If you set a passphrase for your private key, you’ll be prompted to enter it.

What’s New in Ubuntu 24.04/24.10?

Ubuntu 24.04/24.10 brings some exciting improvements that make working with SSH even better. Here are the highlights you need to know:

  • Improved Ed25519 Support – Ubuntu 24.04/24.10 offers enhanced support for the Ed25519 algorithm, making it the preferred choice for secure and fast key generation.
  • Simplified Key Management – The updated ssh-keygen tool now provides better defaults and additional output to guide first-time users.
  • Enhanced Security Configurations – OpenSSH’s default configurations in these versions prioritize stronger encryption protocols and deprecate outdated ones.

Bonus Tip: Managing Multiple Keys

If you work with multiple servers, you can create separate keys for each one. Use the -f option to specify a custom file name:

When connecting, specify which key to use:

ssh -i ~/.ssh/my_custom_key username@server_ip_or_hostname

For a smoother experience, configure your SSH client by editing the ~/.ssh/config file:

Wrapping Up

Generating an SSH key pair in Ubuntu 24.04/24.10 is a straightforward process that brings both heightened security and convenience to your server connections. Whether you’re managing a single server or multiple, using an SSH key pair is a best practice that simplifies authentication and reduces dependence on passwords. So, take a few minutes to set up your key pair and enjoy worry-free remote access. Remember to keep your private key safe, never share it with anyone or store it in not secure locations.

Got any questions or tips to share? Let us know in the comments.

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *