Remotes and GitHub

Authenticate with SSH

Use an SSH key so GitHub can identify your computer without asking for a password on every operation.

SSH authentication lets a Git host identify your computer through a key pair. I use it for every day-to-day push and pull on notes-project.

The pair contains a private key and a public key. The private key stays on your computer. You add the public key to your GitHub account.

Create a modern key with a label that identifies it:

ssh-keygen -t ed25519 -C "[email protected]"

Follow the prompts and protect the private key with a passphrase. Your operating system or SSH agent can remember the unlocked key for a session.

Files ending in .pub contain the public key:

ls -la ~/.ssh

Add the .pub file content to GitHub under SSH keys, then test the connection:

ssh -T [email protected]

On success, GitHub responds with a greeting that includes your username. That proves authentication works. It does not grant access to every repository. Repository permissions still apply.

Point notes-project at an SSH remote URL:

cd notes-project
git remote set-url origin [email protected]:flaviocopes/notes-project.git
git remote -v

Both fetch and push lines should start with [email protected]:.

Wrong URL scheme is a common failure. If origin still uses HTTPS:

https://github.com/flaviocopes/notes-project.git

git push may prompt for a password GitHub no longer accepts for Git operations. Switch to SSH with git remote set-url or use a credential manager with HTTPS deliberately.

If ssh -T [email protected] says Permission denied (publickey), the key is missing from GitHub or your agent is not loading it. Add the .pub file to your account and retry.

The file ending in .pub is safe to copy to a service. Never share the private key. If a key is exposed, remove it from GitHub and replace the pair.

Try this: identify the public and private files in a disposable key pair without printing the private key content.

Lesson completed