I have been using git actively since 2014. When I first started, it was annoying to enter my password every time I cloned and pushed updates to repos. The answer, I was told, was to set up SSH keys. I was amazed! The process was so much faster after I set up SSH key pairs with my laptop, build server, and Github.
Github recommends using an HTTPS connection over SSH, the primary reason being universal availability through firewalls. HTTPS access is slightly less involved, requiring only a GitHub username and password. The downside to connecting via HTTPS is that you will have to enter your username and password when you perform git actions such as pull and push. A workaround for this is to set up a cache for your credentials, but this only stores them for a specified time.
I recommend using SSH because I find it faster, more convenient, and more secure. Faster, because there's no more entering your credentials and more convenient because once your keys are set up, you're good to go. SSH is also more secure than HTTPS. For example, if your account credentials are compromised, an attacker can gain access to your entire GitHub account. If your SSH key is compromised, you have the ability to log in and change/delete your SSH key.
Setting up an SSH key is easy, as demonstrated below:
Open a terminal and type the following:
You will be asked to enter a file to save the key. Pressing enter will save your key pair in the default location.
Next, you will be asked to enter a passphrase. If you don't want to associate a password with the key, just pres enter to leave this blank.
Now that the key pair has been created, you have to start the SSH-Agent so your key can be added.
Now add your key to the SSH-Agent:
The last step is to add the public key to your GitHub account. Go into your GitHub account settings, to "SSH and GPG Keys". Click the green button to add a new key. Add a title and copy the public key from your .ssh folder (or wherever you store the key).
And that's it, SSH is setup for your account. Get started by selecting "use SSH" on the green "clone or download" button.
Top comments (3)
Let me guess, you use linux.
Because on windows or mac os* has in-built credential manager so you dont need to login every time in git.
I use both of Win and MacOS, never had to add an ssh key to github unless we talk private repositories thats not under my account.
So it works on mac too?