Avoid SSH passphrase


I recently upgraded my macOS but when I tried to perform an SSH operation, I was asked to enter a passphrase:

git pull
Enter passphrase for key '/Users/remarkablemark/.ssh/id_rsa':
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

I took the following steps to resolve this issue.

Check SSH key

First, check if you have a key pair:

ls -a ~/.ssh/

If you don’t see the following files:

id_rsa
id_rsa.pub

Then you’ll need to generate a new SSH key.

Generate SSH key

To generate an SSH key:

ssh-keygen -t rsa -b 4096 -C "your.email@example.com"

Add SSH key to agent

Start the ssh-agent if it’s not running already:

eval $(ssh-agent -s)
Agent pid 5451

The ssh-agent manages your keys so check if it’s there:

ssh-add -l
The agent has no identities.

Since there are no keys, add your key to the ssh-agent (hit Enter when asked to enter a passphrase):

ssh-add -K ~/.ssh/id_rsa
Enter passphrase for /Users/remarkablemark/.ssh/id_rsa:
Identity added: /Users/remarkablemark/.ssh/id_rsa (/Users/remarkablemark/.ssh/id_rsa)

The -K stores the passphrase in your keychain.

Now you should be able to perform SSH operations without being asked for a passphrase:

git pull
Already up to date.

SSH config

To prevent having to enter a passphrase even after a restart, add the following to your SSH config file ~/.ssh/config:

Host *
  UseKeychain yes
  AddKeysToAgent yes
  IdentityFile ~/.ssh/id_rsa


Please support this site and join our Discord!