For tools on your computer to interact with GitHub (e.g., pushing a local repository to GitHub), you need to set up a way for them to authenticate you to GitHub. You can use either HTTPS or SSH for this. Both methods are acceptable, but we recommend HTTPS (as does GitHub). That said, Mac and Linux users may find SSH slightly more convenient.
When accessing a GitHub repository, the URL format depends on the protocol you use:
https://github.com/
https://github.com/johndoe/myrepo.git
git@github.com:
git@github.com:johndoe/myrepo.git
Use the matching URL based on the protocol you chose for authentication.
Step 1: Create a Personal Access Token (PAT)
Settings
→ Developer settings
→ Personal access tokens
→ Tokens (classic)
.Generate new token
dropdown, and choose Generate new token (classic)
.Note
), an expiration date, and scopes (i.e., operations for which this PAT can be used). We recommend selecting the following scopes:Step 2: Configure Git to cache your credentials
To avoid having to enter username/PAT every time, you can ask Git to store it securely on your computer, as follows:
Configure Git to use the built-in Credential Manager by running:
git config --global credential.helper manager-core
macOS uses the Keychain by default, so your PAT is stored automatically after the first use. No further action needed.
Configure Git to use credential cache by running:
git config --global credential.helper cache
Step 3: Use the credentials once, to cache it.
When you perform your first Git operation that contacts GitHub (like pushing or pulling), Git will prompt you for a username and password.
To trigger the above step, you can attempt to access a remote private repository:
git clone https://github.com/se-edu/samplerepo-private.git
The operation will fail, but it will trigger the authentication mechanism which will ask for your credentials, and cache them for future use.
ls -al ~/.ssh
Look for files like id_ed25519.pub
.
ssh-keygen -t ed25519 -C "your_email@example.com"
In a PowerShell (Admin) window:
Get-Service -Name ssh-agent | Set-Service -StartupType Manual
Start-Service ssh-agent
ssh-add ~/.ssh/id_ed25519
Copy your public key:
cat ~/.ssh/id_ed25519.pub
Then add it to GitHub → Settings → SSH and GPG Keys.
ssh -T git@github.com
Say yes
when prompted, and you should see a welcome message with your username.
Perform these steps within your WSL distribution.
ls -al ~/.ssh
Look for id_ed25519.pub
or similar.
ssh-keygen -t ed25519 -C "your_email@example.com"
Press Enter to accept all defaults.
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
cat ~/.ssh/id_ed25519.pub
Paste the output into GitHub → Settings → SSH and GPG Keys.
ssh -T git@github.com
ls -al ~/.ssh
Look for files named id_rsa.pub
, id_ecdsa.pub
, or id_ed25519.pub
. If you have one, skip to step 4.
ssh-keygen -t ed25519 -C "your_email@example.com"
Press Enter to accept all defaults (including empty passphrase).
Start the ssh-agent:
eval "$(ssh-agent -s)"
Configure SSH (for macOS Sierra 10.12.2 or later):
touch ~/.ssh/config
Add this to your ~/.ssh/config
file:
Host github.com
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_ed25519
Add your SSH key:
ssh-add --apple-use-keychain ~/.ssh/id_ed25519
Copy your public key to clipboard:
pbcopy < ~/.ssh/id_ed25519.pub
ssh -T git@github.com
Type yes
when prompted, and you should see a message with your username.
ls -al ~/.ssh
Look for id_ed25519.pub
or similar.
ssh-keygen -t ed25519 -C "your_email@example.com"
Press Enter to accept all defaults.
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
cat ~/.ssh/id_ed25519.pub
Paste the output into GitHub → Settings → SSH and GPG Keys.
ssh -T git@github.com
Contributors: Woo Jiahao (@woojiahao)