Labels

Saturday, 30 January 2016

Generate SSH Public Key

SSH Connection to Github account

1. checking existing SSH keys

$ ls -al ~/.ssh
# Lists the files in your .ssh directory, if they exist

2. Add existing SSH Key to Github account

$ pbcopy < ~/.ssh/id_rsa.pub
Then add this copied key to Github account SSH Key 

3. Test SSH connection

$ ssh -T git@github.com
after a few steps and add passphrase, it will successfully with below msg - 
"Hi wzunix! You've successfully authenticated, but GitHub does not provide shell access."
If get error git@github.com: Permission denied (publickey).
Solution: Generate a new SSH Key

4. Generate a new SSH Key and add to ssh-agent

$

5. Changing passphrase for SSH Key

sudo ssh-keygen -p -f ~/.ssh/id_rsa
Note: Need to use 'sudo', otherwise will get 'Saving key "/Users/wzunix/.ssh/id_rsa" failed: Permission denied'



Step 2: Add new SSH key to Github account:













Step 2.1 on Github page, Add SSH Key



Step 1: To generate a new SSH key, copy and paste the text below, making sure to substitute in your email address. The default settings are preferred, so when you're prompted to "Enter a file in which to save the key", just press Enter to continue.
ssh-keygen -t rsa -C "your_email@example.com"
# Creates a new ssh key, using the provided email as a label
# Generating public/private rsa key pair.
# Enter file in which to save the key (/Users/you/.ssh/id_rsa): [Press enter]
Next, you'll be asked to enter a passphrase.
Strongly recommend a very good, secure passphrase. For more information, see Working with SSH key passphrases.
# Enter passphrase (empty for no passphrase): [Type a passphrase]
# Enter same passphrase again: [Type passphrase again]
Which should give you something like this:
# Your identification has been saved in /Users/you/.ssh/id_rsa.
# Your public key has been saved in /Users/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@example.com
Then add your new key to the ssh-agent:
# start the ssh-agent in the background
eval "$(ssh-agent -s)"
# Agent pid 59566
ssh-add ~/.ssh/id_rsa