How to use a Private key for SSH authentication

Use a Private key for SSH authentication

What’s a private key?

Even the most complex passwords cannot match the cryptographic strength of private keys. With SSH, private keys significantly improve security by relieving users of the burden of remembering complex passwords (or worse yet, writing them down).

Let’s first Open a terminal and generate a private key.

Step 1 : Check to see if you already have an SSH key.

$ ls ~/.ssh


Step 2 : Create SSH key.

$ ssh-keygen


– The command will prompt you for a file name. By default, the ssh key pairs are stored as id_rsa and for private key and public key, respectively.

$ Enter file in which to save the key (/home/ubuntu/.ssh/id_rsa):

To use the default filename, press ENTER and proceed.

In the next part, enter a passphrase to secure your key pairs. You can skip this by pressing ENTER.

$  Enter passphrase (empty for no passphrase):

$  Enter same passphrase again:

Step 3 : Copy private key to the remote host.

$ ls ~/.ssh


To use the SSH key pair you created, we must first copy the public key to the remote server. Fortunately, OpenSSH includes the ssh-copy-id function to do this.

$ ssh-copy-id [email protected]_server_ip

Step 4 : SSH using The Private Key.

$ ssh [email protected]_server_ip

You have now successfully utilized SSH key-based authentication. By eliminating password login, you may provide an extra degree of protection.


This tutorial has shown you how to create SSH key pairs and copy the keys to remote hosts. The steps mentioned above allow you to authenticate SSH sessions without using a password. Furthermore, you may control numerous servers at the same time with a single key pair.