Home  »  ArticlesGuidesHow ToTechnologyTools   »   Ensure Secure Access: Setting Up SSH Keys on Ubuntu 22.04

Ensure Secure Access: Setting Up SSH Keys on Ubuntu 22.04

In today’s interconnected world, secure access to remote systems is paramount. SSH (Secure Shell) keys provide a robust method for authentication, eliminating the need for passwords and enhancing security. In this comprehensive guide, we’ll walk you through the process of setting up SSH keys on Ubuntu 22.04, ensuring seamless and secure access to your systems.

What are SSH Keys?

SSH keys consist of a pair of cryptographic keys: a public key and a private key. The public key is placed on the server, while the private key is kept securely on your local machine. When connecting to the server, the SSH client uses the private key to authenticate with the server, providing a secure and convenient method for access.

Step 1: Check for Existing SSH Keys

Before generating new SSH keys, it’s essential to check if you already have existing keys on your Ubuntu 22.04 system. You can do this by navigating to the ~/.ssh directory and checking for key files:

$ ls ~/.ssh

If you see files named id_rsa and id_rsa.pub, you already have SSH keys available.

Step 2: Generate SSH Key Pair

If you don’t have existing SSH keys, you can generate a new key pair using the ssh-keygen command:

$ ssh-keygen -t rsa -b 4096 -C "[email protected]"

Replace "[email protected]" with your email address. This command will create a new SSH key pair with RSA encryption and a 4096-bit key length.

Step 3: Secure the Private Key

Once the SSH key pair is generated, it’s crucial to secure the private key. Set appropriate permissions to restrict access to the private key file:

$ chmod 600 ~/.ssh/id_rsa

Step 4: Add Public Key to Server

To use SSH keys for authentication, you need to add the public key (id_rsa.pub) to the authorized_keys file on the server you wish to access. You can do this manually by copying the contents of the public key file and appending them to the ~/.ssh/authorized_keys file on the server.

Step 5: Test SSH Key Authentication

With the SSH keys set up, you can now test the authentication by connecting to the server:

$ ssh username@hostname

Replace username with your username on the server and hostname with the hostname or IP address of the server.


Setting up SSH keys on Ubuntu 22.04 enhances security and simplifies remote access to your systems. By following these steps to generate and configure SSH keys, you establish a robust authentication mechanism, eliminating the reliance on passwords and reducing the risk of unauthorized access. Embrace the power of SSH keys for seamless and secure remote administration of your Ubuntu systems.

Found this article interesting? Follow Brightwhiz on Facebook, Twitter, and YouTube to read and watch more content we post.

Available under:
Articles, Guides, How To, Technology, Tools