Setup GitHub authentication on Mac

You have to configure Git with your GitHub account and set up secure authentication and the recommended approach is to use SSH keys.

Step 1: Generate a New SSH Key (if needed)

Open terminal and use this command

ssh-keygen -t ed25519 -C “email@example.com”

Replace "email@example.com" with the email address associated with your GitHub account.

When prompted, press Enter to use the default file location (where key will be saved) and set a passphrase if needed.

Step 2: Add the SSH Key to the SSH Agent

eval “$(ssh-agent -s)”
ssh-add ~/.ssh/id_ed25519

If your key was saved in a different location, replace ~/.ssh/id_ed25519 with the correct directory path.

Step 3: Add SSH Key to Your GitHub Account

Copy the SSH key

pbcopy < ~/.ssh/id_ed25519.pub

Then go to GitHub SSH settings and click New SSH key. Paste your key and save.

Step 4: Test SSH Connection

Test your SSH connection by running this command. You will see a success message if everything is set up correctly, as per above steps.

ssh -T git@github.com