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.
~/.ssh/id_rsa.github
~/.ssh/id_rsa.github.pub
Add public keys to GitHub
- Goto GitHub settings page:
- Add you public keys to GitHub by copying content from
~/.ssh/id_rda.github.pub
-
Once you add your public key, you should see it in the list of keys in your account.
GitHub config on you local machine
- 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 -
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.
-
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
To see all git config values and validate if remote.origin.url has been set
$ git config -l