How to setup password less git push for github

You can use user and password based authentication to push git changes to GitHub. But it is cumbersome to type user and password with every push. A better alternative is to use ssh key for authentication while pushing. Here are steps to setup ssh key based password less authentication with GitHub.

Create a ssh public and private keys

First create a public/private key for authentication. You can create ssh key pair (without passphrase) as mentioned in the linked tutorial. You can use the following location for two generated files.

  1. ~/.ssh/id_rsa.github
  2. ~/.ssh/id_rsa.github.pub

Add public keys to GitHub

  1. Goto GitHub settings page:
    github-setting-menu-item
  2. Add you public keys to GitHub by copying content from ~/.ssh/id_rda.github.pub
    github-ssh-add-key-interface
  3. Once you add your public key, you should see it in the list of keys in your account.
    github-account-ssh-keys-list

GitHub config on you local machine

  1. First setup remote.origin.url using
    $ git config  remote.origin.url git+ssh://git@github.com/youriserid/repoid.git
    

    Old : https://github.com/youriserid/repoid.git
    New: git+ssh://git@github.com/youriserid/repoid.git

  2. To see all git config values and validate if remote.origin.url has been set

    $ git config -l
    
  3. Now add the following lines to you ~/.ssh/config to ssh that for github servers we want to use git key

    Host github.com
    IdentityFile ~/.ssh/id_rsa.github
    

    Test that you can ssh to github

    $ ssh -T git@github.com
    Hi user1! You've successfully authenticated, but GitHub does not provide shell access.
    
  4. Now make any test change and commit locally. To push to origin run the following and it should not ask for password.

    $ git push origin master
    
Share this article: share on Google+ share on facebook share on linkedin tweet this submit to reddit

Comments

Click here to write/view comments