EduFlow
Git & GitHub
0%

Section 3 · Collaborating on GitHub

Authenticating with SSH Keys or HTTPS

14 min3 min readPut in order

Lesson at a glance

Authenticate Git with GitHub over HTTPS through a credential manager or over SSH with an ed25519 key, test the connection, and switch a remote between the two URL styles.

  1. 1The two protocols
  2. 2Option 1: HTTPS with a credential manager
  3. 3Option 2: SSH keys
  4. 4Pointing the remote at the right protocol

No video here — just the real thing: a written lesson, runnable examples, a quiz and practice.

Your first git push asked for a username and password. GitHub needs proof that the person pushing to maya-okafor/portfolio is Maya. It won’t accept your account password for that; it hasn’t since 2021, when it switched Git operations to stronger credentials. You have two good options, and you only set either one up once per computer.

The two protocols

The remote URL decides how Git talks to GitHub:

Text
https://github.com/maya-okafor/portfolio.git    HTTPS
git@github.com:maya-okafor/portfolio.git        SSH

HTTPS authenticates with a token. A credential manager gets one by sending you through GitHub’s normal browser sign-in (including two-factor) and stores it in your system’s secure storage. SSH authenticates with a key pair you generate; GitHub stores the public half and checks you hold the private half.

Which should you pick? HTTPS with a credential manager is the easiest to set up and works on any network that allows web browsing. SSH takes five more minutes, doesn’t expire (GitHub only removes a key after a year without use), and is what many developers use day to day. Both are equally secure when set up properly. If in doubt, start with HTTPS; you can switch any time.

Option 1: HTTPS with a credential manager

Git Credential Manager (GCM) comes with Git for Windows. On macOS, install it with Homebrew (brew install --cask git-credential-manager); on Linux, follow the install guide on its GitHub page. The next time Git needs credentials, a browser window opens, you sign in to GitHub and approve, and GCM stores the token. You won’t be asked again.

If you’ve installed the GitHub CLI, it can do the same job:

Terminal
gh auth login

Choose GitHub.com, HTTPS, and answer yes to “Authenticate Git with your GitHub credentials?”. It signs you in through the browser and configures Git to use it as a credential helper.

The manual alternative is a personal access token: create one under Settings, Developer settings, and paste it where Git asks for a password. It works, but you have to manage expiry and storage yourself, so prefer a credential manager on your own machine and keep tokens for automation.

Option 2: SSH keys

Generate a key pair. Ed25519 is the modern default:

Terminal
ssh-keygen -t ed25519 -C "maya.okafor@example.com"

Press Enter to accept the default location, then set a passphrase. The passphrase protects the private key if your laptop is ever stolen. The comment after -C is a label to help you recognise the key later.

You now have two files:

  • ~/.ssh/id_ed25519, the private key. It never leaves this machine.
  • ~/.ssh/id_ed25519.pub, the public key. Safe to share; this is what GitHub gets.

Load the key into the SSH agent so you type the passphrase once per session, not on every push:

Terminal
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519

On macOS, ssh-add --apple-use-keychain ~/.ssh/id_ed25519 stores the passphrase in your Keychain; GitHub’s guide shows the matching ~/.ssh/config lines. Then copy the public key (pbcopy < ~/.ssh/id_ed25519.pub on macOS, or open the file and copy its single line), and on GitHub go to Settings, SSH and GPG keys, New SSH key, and paste it.

Test the connection:

Terminal
ssh -T git@github.com

The first time, SSH asks you to confirm GitHub’s host fingerprint; compare it with the fingerprints GitHub publishes in its docs before typing yes. Success looks like this:

Text
Hi maya-okafor! You've successfully authenticated, but GitHub does not provide shell access.

That “does not provide shell access” line is normal; you’re not logging in to a server, only proving who you are.

Pointing the remote at the right protocol

Authentication follows the URL. If you set up SSH but cloned with HTTPS, Git keeps using HTTPS. Check and switch:

Terminal
git remote -v
git remote set-url origin git@github.com:maya-okafor/portfolio.git
git push

Going the other way is the same command with the https:// URL.

With pushing sorted, you can start working the way teams do on GitHub: through pull requests.

Key takeaways

  • GitHub doesn’t accept your account password for Git operations; use a credential manager, a personal access token, or an SSH key.
  • Git Credential Manager (or gh auth login) signs you in through the browser once and stores the credential securely.
  • An SSH key pair has a private half that never leaves your machine and a public .pub half that you add to GitHub.
  • ssh -T git@github.com tests SSH authentication and greets you by username when it works.
  • The remote URL decides the protocol: https://github.com/… uses HTTPS, git@github.com:… uses SSH; switch with git remote set-url.

Further reading

Check your understanding

4 questions

Question 1 of 4

git push over HTTPS asks for a password. You type your GitHub password and get Support for password authentication was removed. What should you do?

Question 2 of 4

After running ssh-keygen -t ed25519, which file do you paste into GitHub’s “New SSH key” form?

Question 3 of 4

SSH works (ssh -T git@github.com greets you), but git push still asks for a username and password. Why?

Question 4 of 4

You’re on a network that blocks port 22. Which option keeps Git working with the least fuss?

Practice

Put in order

Set up SSH for the portfolio

You’ve decided to push the portfolio over SSH. Put the setup steps in the order that works, from no key at all to a successful git push over SSH. Finish all the local key work (create the key, load it into the agent) before you touch GitHub, and prove SSH works before you change the repository.

Use the arrow buttons to reorder.

  1. 1Run git remote set-url origin git@github.com:maya-okafor/portfolio.git, then git push.
  2. 2Start the agent and run ssh-add ~/.ssh/id_ed25519.
  3. 3Run ssh -T git@github.com and check it greets you by username.
  4. 4On GitHub, open Settings, SSH and GPG keys, New SSH key, and paste it.
  5. 5Copy the contents of ~/.ssh/id_ed25519.pub.
  6. 6Run ssh-keygen -t ed25519 -C "maya.okafor@example.com" and set a passphrase.