Git / SSH error 'Permission denied (publickey)' on Mac OS

  • Posted on: 12 December 2019
  • By: stillfinder

Usually the problem appears if your key isn't loaded into your SSH agent. You may run into this issue if you've recently restarted your system.

Check to see if your SSH key is loaded:

ssh-add -l

If you don't see your key listed, add it by entering ssh-add followed by the path to the private key file:

ssh-add ~/.ssh/<private_key_file>

As of macOS Sierra 10.12.2 Apple added an ssh_config option called UseKeychain which allows a 'proper' resolution to the problem. Add the following to your ~/.ssh/config file:

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