Remotes and GitHub
Authenticate with SSH
Use an SSH key so GitHub can identify your computer without asking for a password on every operation.
8 minute lesson
SSH authentication lets a Git host identify your computer through a key pair.
The pair contains a private key and a public key. The private key stays on your computer. You add the public key to the account on the Git host.
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. Inspect the names carefully before copying anything:
ls -la ~/.ssh
Add the public key content to GitHub, then test the SSH connection using GitHub’s documented test command. A successful authentication does not grant access to every repository; repository permissions still apply.
Use an SSH remote URL:
git remote set-url origin [email protected]:flaviocopes/myrepo.git
git remote -v
The file ending in .pub is safe to copy to a service. Never share the private key.
If a key is exposed, remove its public counterpart from services and replace the pair. Do not commit keys to a repository.
Exercise: identify the public and private files in a disposable key pair without printing the private key content.
Lesson completed