10

I have tried the following:

ssh-add -K ~/.ssh/id_rsa

This seems to work until I end my terminal session, but then I get prompted for my passphrase again with a new session.

Here is what I see after running the command above:

Identity added: /Users/xxx/.ssh/id_rsa (/Users/xxx/.ssh/id_rsa)

I am on iTerm2 Build 3.0.13 with zsh: stable 5.3.1 running on macOS Sierra 10.12.2

Abram
  • 39,950
  • 26
  • 134
  • 184

2 Answers2

10

One solution is to add the command in ~/.profile or ~/.bashrc file. Then every time you open a new terminal the command will be executed automatically.
Since you are using zsh you need to add the command in ~/.zprofile or ~/.zshrc file.

ssh-add -K ~/.ssh/id_rsa &> /dev/null

The &> /dev/null is to avoid seeing the Identity added message everytime you open a new terminal window.

Sajib Khan
  • 22,878
  • 9
  • 63
  • 73
  • Sajib, I edited your answer as I think you missed that I was using zsh. Thanks the solution works. – Abram Jan 29 '17 at 03:30
  • Yes. I missed `zsh`. Welcome. – Sajib Khan Jan 29 '17 at 03:42
  • 1
    I can confirm that this is also solution for macOS High Sierra. My problem was ssh-add -A doesn't add to keychain.So every time I have to run ssh-add -K path/to/key – ErcanE Sep 30 '17 at 13:44
5

Can try ssh-add -K again or edit your ~/.ssh/config to enable the option:

Host * UseKeychain yes

If ssh-add states could not connect, try setting it up with:

eval $(ssh-agent)

Similar to: https://superuser.com/a/1158050

Community
  • 1
  • 1
  • 2
    I think the issue was not having `UseKeychain yes` in my ssh config file. I have updated that and confirmed that the key was added using `ssh-add -l` – Abram Jan 11 '17 at 23:49
  • Hey, I am being asked for my ssh passphrase again. So this did not appear to fix my issue as I has assumed. Removing the check/tick to encourage other answers. Very frustrated. – Abram Jan 22 '17 at 23:13