Skip to content

GitHub Authentication

Authentication in Git is the process of verifying the identity of the user accessing a Git repository. To authenticate, you must provide identification that the Git server can verify.


Authentication Methods

Keeping authentication information secure is essential, as anyone with access can interact with your repository. For HTTPS, use strong passwords and enable two-factor authentication (2FA). For SSH, store your private key securely and use a passphrase.

HTTPS Authentication

Authenticate using your GitHub username and password. When pushing or pulling changes, Git prompts for credentials. The remote URL includes your username:

https://github.com/yourusername/yourrepository.git

SSH Authentication

Authenticate using an SSH key pair. SSH keys allow passwordless authentication. Create a public/private key pair and upload the public key to GitHub. The private key remains on your computer.

The remote URL for SSH authentication:

git@github.com:yourusername/yourrepository.git

Your private key file must follow standard naming conventions:

  • id_dsa
  • id_rsa
  • id_ecdsa
  • id_ed25519
  • id_xmss

To use SSH, add your public key to GitHub under SSH and GPG Keys. For local repositories, set the origin to SSH:

git remote set-url origin git@github.com:username/repository.git

If you have multiple keys, specify which to use:

[Environment]::SetEnvironmentVariable("GIT_SSH_COMMAND", "ssh -i C:\\Users\\userName\\.ssh\\yourspecifickeyfile", "User")

Test SSH connectivity to GitHub:

ssh -T -