Sunday 25 November 2012

Generate SSH Key






To use SSH keys to establish a secure connection between your computer and GitHub. Here is the steps to generate SSH keys and adding the public key to your Github account.

Step 1: Check for SSH keys

 Check for existing ssh keys on your computer by running the command given below:
$ cd ~/.ssh 
# Checks to see if there is a directory named ".ssh" in you user        directory                                                
If it shows "No such file or directory", skip to step 3. Else go to step 2.

Step 2: Backup and remove the existing key

Back the old SSH directory up and remove it:
$ ls
# Lists all the subdirectories in the current directory
config  id_rsa  id_rsa.pub  known_hosts

$ mkdir key_backup
# Makes a subdirectory called "key_backup" in the current directory

$ cp id_rsa* key_backup
# Copies the id_rsa keypair into key_backup

$ rm id_rsa*
# Deletes the id_rsa keypair
Step 3: Generate a new key

To generate a new SSH key, enter the code given below. To make default settings, when asked to enter a file in which to save the key, just press enter.
$ ssh-keygen -t rsa -C "your_email@youremail.com"
# Creates a new ssh key using the provided email
Generating public/private rsa key pair.
Enter file in which to save the key (/home/you/.ssh/id_rsa):
You need to enter passphrase.
Enter passphrase (empty for no passphrase): [Type a passphrase]
Enter same passphrase again: [Type passphrase again]
When you enter the passphrase, it shows something like this:
Your identification has been saved in /home/you/.ssh/id_rsa.
Your public key has been saved in /home/you/.ssh/id_rsa.pub.
The key fingerprint is:01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db                       your_email@youremail.com
Step 3: Add SSH key to Github

Run the following code to copy the key to your clipboard.
$ sudo apt-get install xclip
# Downloads and installs xclip
$ xclip -sel clip < ~/.ssh/id_rsa.pub
# Copies the contents of the id_rsa.pub file to your clipboard
Now,

1. Go to Github Account settings.
2. Click on SSH keys in the left sidebar.
3. Click on Add SSH key.
4. Paste your key into the Key field.
5. Click Add key
6. Confirm the action by entering your Github password.


[Expecting Your Valuable Comments]
Thank You

No comments:

Post a Comment