Passwords can be guessed or leaked. SSH keys use a pair of files, so the private half never leaves your machine.
To set one up:
ssh-keygen -t ed25519 -C "[email protected]"
Accept the default location and set a passphrase. The passphrase protects the key if someone copies the file.
Then:
- Start the agent and add the key with
ssh-add. - Copy the contents of the
.pubfile into your GitHub account under SSH keys. - Test the connection with
ssh -T [email protected].
Never share the private key file, and never commit it to a repository. If you think a key has leaked, delete it from GitHub and generate a new one.