On using GitHub with git, after making any changes, while pushing or on pulling from GitHub, you need to supply username and password. This is because you have HTTPS mechanism to pull or push code to/from GitHub. To push or pull without supplying username and password, you need to setup SSH protocol.
SSH is a key based mechanism where you will generate keys. There will be private and public key when you generate one. The private key will be in the client (The machine from which you are accessing) and need to place the public key in the server side. So, whenever a request is made from client side to server using SSH protocol, the key combination will be verified and authenticated.
So, in GitHub’s case also, the authentication will be done by the key-pair in background and you don’t need to spend time in entering username and password each time you communicate to GitHub.
In order to set a key — check if you already have any key generated. Check for existing keys in below location depending on your Operating system.
- Windows — C:\Users\<Username>\.ssh\
- Linux — /home/username/.ssh/ (~/.ssh/)
If you do not have a key, generate key using below steps.
- Open Terminal
- Execute following command:
ssh-keygen -t rsa -b 4096 -C "firstname.lastname@example.org"
- If prompted for password or location, just keep defaults and press enter
Once you have the keys follow below steps:
- Open the id_rsa.pub in the above mentioned location
- Copy the content of the files
- Navigate to https://github.com/settings/keys
- Click on New SSH Key
- Enter any title
- Paste the public key you have copied
- Click add ssh key/Save
This brings you into a successful ssh association.