Using SSH keys with Github

Using SSH keys to interact with Github is much more convenient that typing username and password all the time. Follow below steps to use this method of authentication.

1. Generate a new SSH key pair with the below command.

ssh-keygen -t rsa -b 4096 -C "email@youremail.com"

2. Store the SSH key pair in .ssh folder.

3. Login to Github and add the contents of the public key as an authorized key in github settings.

4. Run the SSH agent

eval "$(ssh-agent -s)"

5. Add the key file (-K flag for mac OS only, no need inside Homestead)

ssh-add -K ~/.ssh/your-key-name

6. Set the remote url for the repository (do this inside the local repo directory)

git remote set-url origin git@github.com:name/repo

7. Change permissions for the key file to 600

chmod 600 ~/.ssh/key-to-alter

8. Test all is working

ssh -T git@github.com

If this command comes back with a success message, everything should be set up and username and password will not be required.

Posted in Git