What are SSH Keys?

SSH Key

SSH keys are an access credential used in SSH protocol (Secure Shell). A secure shell is a network protocol, which helps to login from one computer to another securely, as well as to manage networks, operating systems, and configurations. Functionally, SSH keys are nearly the same as passwords, but it’s more secure to log into a server with SSH keys than use only passwords because decrypt SSH is very difficult, almost impossible.

SSH keys always come in pairs, and each of these pairs is composed of a public key and a private key. These two are types of keys.

  1. Public keys, also known as authorized keys, determine who can access each system.
  2. Private or identity keys identify users and give them access.

Watch a course Git & GitHub - The Practical Guide

How To Set Up SSH Keys?

You need public-key cryptographic algorithms to generate SSH keys, mostly used of which are RSA key and DSA key. SSH keys are set up with the help of a key generation tool.

Create an SSH key on Mac and Linux

As these two operating systems have modern terminal applications, that combine with SSH package, the steps of creating an SSH key are the same for both of them.

  1. Open a command terminal and run the following:
    ssh-keygen -t rsa -b 4096 -C "[email protected]"
  2. Then you have to choose the file location.
    > Enter a file in which to save the key (/Users/you/.ssh/id_rsa): [Press enter]
  3. Then you should add a secure passphrase, which will be required any time the SSH key is used.
    > Enter passphrase (empty for no passphrase): [Type a passphrase]
    > Enter same passphrase again: [Type passphrase again]
  4. Add the new SSH key to the ssh-agent

The ssh-agent is a tool responsible for holding private keys, but it also arranges requests to sign SSH requests with the private keys for security purposes.

Execute the following code to make sure that the ssh-agent code is running:

$ eval "$(ssh-agent -s)"
> Agent pid 59566

If the ssh-agent code is running, add the new SSH key to the local SSH agent by executing the following command:

ssh-add -K /Users/you/.ssh/id_rsa

Create an SSH Key on Windows

You need Git Bash to create an SSH key on the Windows operating system. If you have it, you can generate the key following the same steps as given above.

Practice Your Knowledge

What are important aspects of SSH keys in the context of Git?

Quiz Time: Test Your Skills!

Ready to challenge what you've learned? Dive into our interactive quizzes for a deeper understanding and a fun way to reinforce your knowledge.

Do you find this helpful?