- Generate keys for your github user email id :
ssh-keygen -t rsa -b 4096 -C "nsuvarna@pivotal.io"
- When prompted for the file to save the key, create a new file, in this case
id_rsa_pivotal
Enter file in which to save the key (/Users/nsuvarna/.ssh/id_rsa):
/Users/nsuvarna/.ssh/id_rsa_pivotal
- Add the key to github settings : https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account/
pbcopy < ~/.ssh/id_rsa_pivotal.pub
- Repeat steps 1-3 for another account
- Edit
~/.ssh/config
file and add the following :
Host pivotal
Hostname github.com
User git
IdentityFile ~/.ssh/id_rsa_pivotal
PubkeyAuthentication yes
Host personal
Hostname github.com
User git
IdentityFile ~/.ssh/id_rsa
PubkeyAuthentication yes
for more details on ssh config
file, refer to this article
ssh-add
to tell SSH about the key you want to use to authenticate on GitHub.ssh-add
adds private key identities (from your ~/.ssh directory) to the authentication agent (ssh-agent), so that the ssh agent can take care of the authentication for you, and you don’t have type in passwords at the terminal
ssh-add ~./ssh/id_rsa_personal
ssh-add ~./ssh/id_rsa_pivotal
List the loaded keys
ssh-add -l
- Now you’ve got your keys in place, let’s poke github and see if it recognizes us
ssh -T pivotal
Hi nikhilsuvarna! You've successfully authenticated, but GitHub does not provide shell access.
- Cloning from a private repo eg from a private repo in the
pivotal-gss
github org :
git clone git@pivotal:pivotal-gss/labpass
Note the use of the @pivotal
- This maps to the alias pivotal
in the ~/.ssh/config
file for github user nikhilsuvarna
8.1 IF you have the wrong origin set, then use the following to change the origin :
git remote add origin git@pivotal:nikhilsuvarna/tech-talks.git
fatal: remote origin already exists
git remote set-url origin git@pivotal:nikhilsuvarna/tech-talks.git
8.2 Check remote origin
git remote show origin
- Push a commit to a private repo
git remote add origin git@pivotal:pivotal-gss/sample-repo.git
git push -u origin master
note the @pivotal
should match the alias in the ssh config file
from step 5.
- Generate API token :
https://help.github.com/articles/creating-an-access-token-for-command-line-use/
git config --local github.token “036c0ca0283355698fda7e94a60eb4f9172c8054"