Easy Steps To Generate SSH key pairs in Linux

In this article, we want to teach you how to generate SSH key pairs in Linux. You can generate SSH keys in all distributions like Centos 7, Ubuntu 22.04, Debian 12, Fedora, etc. Let’s start with a basic introduction to SSH key pairs and start to generate them.

What are SSH key pairs?

SSH key pairs are two cryptographically secure keys that can be used to authenticate a client to an SSH (Secure Shell) server. Each key pair consists of a public key and a private key. As the SSH protocol is widely used for communication in cloud services, network environments, file transfer tools, configuration management tools, and other computer-dependent services, most organizations use SSH keys to authenticate identity and protect those services from unintended use or malicious attacks.

Now that you have become familiar with SSH key pairs, you can follow the steps below to generate them in Linux.

Learn To Generate SSH key pairs in Linux

To generate SSH key pairs in Linux, you must log in to your server as a root or non-root user with sudo privileges. For this purpose, you can check the Orcacore website and search for the Initial Setup guides for Linux distributions.

Steps to Create an SSH key in Linux

To create an SSH key in Linux follow the steps below:

1) Check for existing SSH keys

Run this command in your terminal to check your existing SSH keys:

cd ~/.ssh

If you see “no such file or directory”, it means that there aren’t any existing keys in your Linux system.
So check to see if you have a key with the following command:

ls id_*

2) Backup old SSH keys

If you have existing keys but don’t want to use them, you can backup them by the following command:

# mkdir key_backup
# cp id_rsa* key_backup

3) Generate a new key

If you don’t have an existing SSH key you can easily generate a new key by following these steps:

• For generating public/private key pairs run this command in your terminal:


• Just press <Enter> to accept the default location and file name. If the .ssh directory doesn’t exist, the system creates one for you.
• Enter, and re-enter a passphrase when prompted.
• It’s done; your keys are generated now.

Note: If you want to see all the information about your generated keys you can use the following command:



That’s It. At this point, you have learned the quick steps to generate SSH key pairs in Linux distributions. Hope you enjoy it.

Also, you may like to read the following articles:

Using the ssh-copy-id Command

Top SSH Security Tips on AlmaLinux 9

Enable and Configure SSH on Ubuntu 22.04

Enable and Configure SSH on Debian 11

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!