Generating SSH public/private key pair (Linux / Ubuntu)
Now that in previous post, we have seen how to generate SSH Public / Private keypair in Windows system, how about generating it in Linux or Ubuntu ? Well, here it is.
To generate SSH public/private key pair :
Step 1 : Open a shell or command-line instance on your computer.
Step 2 : Ensure that you don't already have a public key saved to your computer. To do this, run the following command:
$ cd ~/. ssh (# Change into your . ssh folder) $ ls -l (# Lists the files in your . ssh directory, if they exist){ensure you have 700 permission to . ssh i.e. command : $ sudo chmod 700 . ssh }
If the directory and key file (id_rsa. pub) exists, run the following commands to back up the key id_rsa, as this procedure overwrites your current key if it is named id_rsa.
$ mkdir key_backup $ mv id_rsa* key_backup
Step 3 : Generate a new public/private key pair using the keygen command:
$ ssh-keygen -b 4096
The keygen command prompts you for the directory to contain the key.
Generating public/private rsa key pair. Enter file in which to save the key (/home/[user_dir]/. ssh/id_rsa): Press Enter to accept the default location of /. ssh/id_rsa in your user directory. Enter passphrase (empty for no passphrase): [passphrase] Enter same passphrase again: [passphrase]
Substitute [passphrase] with your own text. This is for encrypting the private key on your computer. It's possible to use a blank [passphrase],But if you do this, another user can impersonate you with a copy of the key file.
Note: Be sure to keep track of the [passphrase] since you will need to enter it when using the key.
The keygen command displays the following output:
Generating public/private rsa key pair.
Your identification has been saved in /home/[user_dir]/. ssh/id_rsa.
Your public key has been saved in /home/[user_dir]/. ssh/id_rsa.pub.
The key fingerprint is:
52:96:e9:c8:06:c2:57:26:6d:ef:2f:0c:d9:81:f4:1c username@hostname
{ensure you have 600 permission to id_rsa i.e. command : sudo chmod 600 id_rsa }
Step 4 : In Ubuntu(or any Linux distri. with Xwindows), a similar tool is xclip. I like to make this alias:
alias pbcopy='xclip -selection clipboard' alias pbpaste='xclip -selection clipboard -o'
If you do not have "xclip" :
sudo apt-get install xclip -y
And Then follow the above steps of aliasing..
Step 5 : Copy the key to your clipboard. Run the following code to copy the key to your clipboard:
pbcopy < ~/. ssh/id_rsa. pub # Copies the contents of the id_rsa. pub file to your clipboard
There !! You're all set for using these newly created public / private keypair.
Reference : https://help.github.com/articles/generating-ssh-keys/#platform-linux
Comments
Michael (not verified)
Sat, 05/06/2017 - 23:52
I feel this is among the most
I feel this is among the most important information for me.
And i am glad studying your article. However wanna observation on some basic issues, The site style is perfect,
the articles is really nice : D. Excellent task, cheers
Add new comment