In this post i will quickly explain how to generate a ssh key via command line. This can be helpful for single sign-on or automating logins.
To start generating your ssh key pair you have to start your command line and use the command
You will be asked to to enter the filename in which you want to save the key. You can confirm by pressing enter without any input. Otherwise you could give the path to your file you want to use.
Generating public/private rsa key pair. Enter file in which to save the key (/Users/username/.ssh/id_rsa):
Next you’ll be asked to enter a passphrase. This passphrase is used to encrypt the key you generate. You should choose a passphrase that is cryptographically strong : It should contain a mix of numbers and characters with no further meaning. Also you should make it at least something like 8 characters long. After that you have to type it in again to confirm it.
Enter passphrase (empty for no passphrase): Enter same passphrase again:
After that you can see that two different keys were generated:
Your identification has been saved in /Users/username/.ssh/id_rsa. Your public key has been saved in /Users/username/.ssh/id_rsa.pub.
That’s because one is your private key and the other is the public key. You can use the public key to install on a server. Your private key, on the other hand, should be secured on a save place, like your pc.
The last part you will see in your command line will be something like this:
The key fingerprint is: SHA256:Ea1aIHPE2LBY8RbrQMNTdGN2ULK9gXeEd4XULZgjs9E email@example.com The key's randomart image is: +---[RSA 2048]----+ | .*X= O+oo.+.+o| | +*+=* O*.E + o| | . o=+.+.+*.o . | | + oo.+ | | .oS . | | . | | | | | | | +----[SHA256]-----+
With this output you should be finished generating your own pair of ssh keys, both private and public.
For further reading i would recommend to read the official manual of open ssh.