Sep 5, 2022

SSH Keygen

Public key authentication using SSH (Secure Shell Protocol) is a more secure approach for logging into services than passwords. 

Here's a helpful basic definition:

    "The Secure Shell Protocol is a cryptographic network protocol for operating network services securely over an unsecured network." (Source)
SSH is used between a client and a server both running on the SSH protocol to remotely login into the server and access certain resources through the command line.

There is an open-source version of the SSH protocol (version 2) with a suite of tools called OpenSSH (also known as OpenBSD Secure Shell). This project includes the following tools:

  • Remote operations: ssh, scp, and sftp.
  • Key generation: ssh-add, ssh-keysign, ssh-keyscan, and ssh-keygen.
  • Service side: sshd, sftp-server, and ssh-agent.

Generate an SSH Public Key

We can use ssh-keygen to generate an SSH public key. This will create a key pair containing a private key (saved to your local computer) and a public key (uploaded to your chosen service). 

With the keys, we can login to remote server with public key authentication.

$ ssh-keygen -t rsa -b 4096

Then your SSH private key will be saved at /$HOME/.ssh/id_rsa and public key will be saved in /$HOME/.ssh/id_rsa.pub

To copy the created public key into the authorized_keys file of the remote server, 

$ ssh-copy-id username@remote_host


Links: