Secure Shell (SSH) is a protocol for securely connecting to a remote computer and transferring data. It leverages asymmetric cryptography such as RSA or Ed25519 algorithm to encrypt data when it is exchanged between two computers.
Setting up an SSH key pair is very straight forward. In this post, I will shortly describe how to setup these keys in both Linux and Windows.
First, let’s generate a key pair with the following command:
For Ed25519 algorithm,
ssh-keygen -t ed25519 -C "contact@abdullahhassan.dev"For RSA algorithm with key size 4096 bits,
ssh-keygen -t rsa -b 4096 -C "contact@abdullahhassan.dev"It is very much obvious that the -t option let’s us choose an algorithm, -b option is for key size if the algorithm requires and -C option represents Common Name which in this case is a email address.
Usually the generated key is saved on the .ssh folder on /home in Linux and on User folder in Windows. However, we can save the key files at a different path by using the -f option.
ssh-keygen -t rsa -b 4096 -C "contact@abdullahhassan.dev" -f "/opt/keys/my_key"Here, my_key is the name that will be used to name the key files.
Finally, we can add the generated key into the ssh-agent.
ssh-add "/path/to/private/key/file"