How to Generate RSA key / SSH key in Ubuntu Linux/Windows?
RSA keys (public-private key pair) are required to authenticate your computer in order to access some resource via ssh. It helps you to avoid entering password each time you are trying to access the resources. Following is the quick way you can generate RSA keys and used it when required.
Check for already available SSH Key
Go to Terminal (for Linux) / git bash (for windows)
cd ~/.ssh
You can also check in the default location for windows i.e. 'C:\Users\<username>\.ssh\' folder
Generate RSA Key / SSH Key
ssh-keygen -t rsa -C "your@email_id.com"
Gives following output:
Generating public/private rsa key pair. Enter file in which to save the key (/home/<username>/.ssh/id_rsa):
Press Enter for default location. Then, it gives following output:
Created directory '/home/<username>/.ssh'. Enter passphrase (empty for no passphrase):
Press Enter for no passphrase. (Passphrase is used for extra security purpose, if you enter a passphrase, you either need to re-enter you passphrase everytime ssh authentication is made or, use 'ssh-agent', a tool to manage the passphrase.)
Enter same passphrase again:
Again, Press Enter. You will have following output.
Your identification has been saved in /home/<username>/.ssh/id_rsa. Your public key has been saved in /home/<username>/.ssh/id_rsa.pub. The key fingerprint is: bla:bla:bla:bla your@email_id.com
Congratulations! your RSA key is not successfully generated and stored in home folder.
Add Public RSA Key / SSH Key to your Account
Now, you need to copy 'public key' from RSA key pair (contents of 'id_rsa.pub' file) and paste it into your online account or server. All you need to do is:
cat ~/.ssh/id_rsa.pub
and copy the content displayed up to your email_id, then paste it where you need to. Now you are DONE.
For the first time, ssh authentication is made, the following message can be seen, go ahead and type yes and enter, then that host will be recorded in a file: known_host in ~/.ssh/ folder for later reference
The authenticity of host 'blablabla.com' can't be established. RSA key fingerprint is bla:bla:bla:.... Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'blablabla.com' (RSA) to the list of known hosts.
Why is SSH keys / RSA keys required? How does it work? Lets see, what happens and clear out the concept of ssh authentication using RSA keys...
You generate unique RSA keys pairs i.e. public key and private keys, both are by default store in separate files in .ssh folder inside home i.e. (/home/<username>/.ssh/) 'id_rsa' is private key whereas 'id_rsa.pub' is the public key. You need to copy-paste the content of id_rsa.pub (the public key) to external resources wherever required whereas keep the private key secret. Now every time you perform ssh request, ssh authentication runs during which, the public key you had pasted in external resource makes a match against the private key stored in you computer. If the authentication is successful it allows further access via ssh. Enjoy! If not, recheck you keys in 'id_rsa.pub' and paste it to the external resource.
For further details on How Public Key Cryptography Works? Go to 'Introduction' and then straight to 'how it works?' and 'Description' Section.
Note: external resource mentioned above might be your account in the web which allows you access via ssh, where have to enter rsa public keys, can be your online accounts in github and other repositories (normally inside your account/settings > add ssh keys section) or servers.











