git clone supports both HTTPS and SSH remote URLs. Which should I use? What are the advantages of each?
GitHub's docs don't make a recommendation either way. I recall in 2013 GitHub used to recommend SSH (archive link). Why was that?
git clone supports both HTTPS and SSH remote URLs. Which should I use? What are the advantages of each?
GitHub's docs don't make a recommendation either way. I recall in 2013 GitHub used to recommend SSH (archive link). Why was that?
GitHub have changed their recommendation several times (example).
It appears that they currently recommend HTTPS because it is the easiest to set up on the widest range of networks and platforms, and by users who are new to all this.
There is no inherent flaw in SSH (if there was they would disable it) -- in the links below, you will see that they still provide details about SSH connections too:
HTTPS is less likely to be blocked by a firewall.
The
https://
clone URLs are available on all repositories, regardless of visibility.https://
clone URLs work even if you are behind a firewall or proxy.
An HTTPS connection allows credential.helper
to cache your password.
https://docs.github.com/en/get-started/quickstart/set-up-git#connecting-over-https-recommended
If you clone with HTTPS, you can cache your GitHub credentials in Git using a credential helper. For more information, see "Cloning with HTTPS urls" and "Caching your GitHub credentials in Git."
I assume HTTPS is recommended by GitHub for several reasons
It's simpler to access a repository from anywhere as you only need your account details (no SSH keys required) to write to the repository.
HTTPS Is a port that is open in all firewalls. SSH is not always open as a port for communication to external networks
A GitHub repository is therefore more universally accessible using HTTPS than SSH.
In my view SSH keys are worth the little extra work in creating them
SSH Keys do not provide access to your GitHub account, so your account cannot be hijacked if your key is stolen.
Using a strong keyphrase with your SSH key limits any misuse, even if your key gets stolen (after first breaking access protection to your computer account)
If your GitHub account credentials (username/password) are stolen, your GitHub password can be changed to block you from access and all your shared repositories can be quickly deleted.
If a private key is stolen, someone can do a force push of an empty repository and wipe out all change history for each repository you own, but cannot change anything in your GitHub account. It will be much easier to try recovery from this breach of you have access to your GitHub account.
My preference is to use SSH with a passphrase protected key. I have a different SSH key for each computer, so if that machine gets stolen or key compromised, I can quickly login to GitHub and delete that key to prevent unwanted access.
SSH can be tunneled over HTTPS if the network you are on blocks the SSH port.
https://help.github.com/articles/using-ssh-over-the-https-port/
If you use HTTPS, I would recommend adding two-factor authentication, to protect your account as well as your repositories.
If you use HTTPS with a tool (e.g an editor), you should use a developer token from your GitHub account rather than cache username and password in that tools configuration. A token would mitigate the some of the potential risk of using HTTPS, as tokens can be configured for very specific access privileges and easily be revoked if that token is compromised.
Either you are quoting wrong or github has different recommendation on different pages or they may learned with time and updated their reco.
We strongly recommend using an SSH connection when interacting with GitHub. SSH keys are a way to identify trusted computers, without involving passwords. The steps below will walk you through generating an SSH key and then adding the public key to your GitHub account.
Recommendation: use HTTPS with an OAuth credential helper such as Git Credential Manager or git-credential-oauth.
No more passwords or personal access tokens! The first time you push, the helper will open a browser window to authenticate. Subsequent pushes within storage lifetime require no interaction.
It's possible to argue that using SSHs key to authenticate is less secure because we tend to change our password more periodically than we generate new SSH keys.
Servers that limit the lifespan for which they'll honor given SSH keys can help force users toward the practice of refreshing SSH-keys periodically.
One further reason for favoring HTTPS is that if multiple users are managing code on a central server -- say a development machine -- each user needs to create their own ssh key in order to use the SSH-based connection. If the connection is HTTPS, this issue doesn't exist.
I guess you could argue that it's not so difficult to just have setting up your own key be a part of onboarding to using the server where that project is stored, but it is a further hurdle to getting your work done.
There is no "official" Git recommendation for this, but each Git remote host has its own preferences.
For example, the GitHub website and GitHub CLI both default to HTTPS, for "better interoperability and ease of use". GitLab, on the other hand, recommends SSH in its documentation.
There are advantages and disadvantages to both approaches:
SSH
HTTPS
These recommendations have changed over the years for various reasons.