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': [email protected]: 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:
Then you’ll need to generate a new SSH key.
Generate SSH key
$ ssh-keygen -t rsa -b 4096 -C "[email protected]"
Add SSH key to agent
ssh-agent if it’s not running already:
$ eval $(ssh-agent -s) Agent pid 5451
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)
-Kstores 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.
To prevent having to enter a passphrase even after a restart, add the following to your SSH config file
Host * UseKeychain yes AddKeysToAgent yes IdentityFile ~/.ssh/id_rsa