In my last blog, I quoted
I'm an advocate of using SSH authentication and connecting to services like Github, Gitlab, and many others.
On this, I received a bunch of messages over IRC asking why do I prefer SSH for Git over HTTPS.
I find the Github documentation quite helpful when it comes down to learning the basic operation of using Git and Github. So, what has Github to say about "SSH v/s HTTPS"?
Github earlier used to recommend using SSH, but they later changed it to HTTPS. The reason for the Github's current recommendation could be:
- Ease to start with: HTTPS is very easy to start with, as you don't have to set up your SSH keys separately. Once the account is created, you can just go over and start working with repositories. Though, the first issue that you hit is that you need to enter your username/password for every operation that you need to perform with git. This can be overcome by caching or storing the password using Git's credential storage. If you cache, then it is cached in memory for a limited period after which it is flushed so you need to enter your credentials again. I would not advise storing the password, as it is stored as plain-text on disk.
- Easily accessible: HTTPS in comparison to SSH is easily accessible. Why? You may ask. The reason is a lot of times SSH ports are blocked behind a firewall and the only option left for you might be HTTPS. This is a very common scenario I've seen in the Indian colleges and a few IT companies.
Why do I recommend SSH-way?
SSH keys provide Github with a way to trust a computer. For every machine that I have, I maintain a separate set of keys. I upload the public keys to Github or whichever Git-forge I'm using. I also maintain a separate set of keys for the websites. So, for example, if I have 2 machines and I use Github and Pagure then I end up maintaining 4 keys. This is like a 1-to-1 connection of the website and the machine.
SSH is secure until you end up losing your private key. If you do end up losing your key, even then you can just login using your username/password and delete the particular key from Github. I agree, that the attacker can do nasty things but that would be limited to repositories and you would have control of your account to quickly mitigate the problem.
On the other side, if you end up losing your Github username/password to an attacker, you lose everything.
I also once benefitted from using SSH with Github, but IMO, exposing that also exposes a vulnerability so I'll just keep it a secret :)
Also, if you are on a network that has SSH blocked, you can always tunnel it over HTTPS.
But, above all, do use 2-factor authentication that Github provides. It's an extra layer of security to your account.
If you have other thoughts on the topic, do let me know over twitter @yudocaa, or drop me an email.