Why won't my ssh/config file load my ssh keys into my ssh agent after reboot?

I've recently started using GitHub with ssh. I successfully generated my ssh keys, added them to my agent and stored the password in my keychain. Unfortunately, no matter what I try, I can't get my config file to load my ssh key back into my ssh agent when I reboot my Mac.

I've tried the following config text, both with and without the '.github.com' reference:


Host *.github.com

AddKeysToAgent yes

UseKeychain yes

IdentityFile ~/.ssh/id_github


I've tried matching the file permissions to the private key 'chmod 600' and the known hosts file 'chmod 644'.

I've checked that the file doesn't have any extra permissions or extended attributes.

Can anyone tell me where I am going wrong and what I can do to get it working.


Posted on Jan 30, 2023 8:31 AM

Reply

Similar questions

3 replies

Feb 1, 2023 6:16 AM in response to SausageSandwich

SausageSandwich wrote:

I am new to SSH, however my understanding is that after generating a passphrase protected SSH key

That's your problem. I think I tried using passphrase-protected ssh keys when I first started too. Later you realize what a hassle it is and never do that again.

adding it to the mac's SSH Agent securely caches the decrypted private key and makes it available so that the user doesn't continually have to enter the keys passphrase. The agent used to do this automatically, but Apple changed things a couple of years back and now the keys have to be added to the agent manually after every reboot.

Yes. It has been many years since I've seen a question about ssh-agent. Even back then, I had long ago stopped using passphrases. I'm not sure that the keychain and ssh-agent are even linked anymore. You may need to just ignore ssh-agent entirely and login. When you enter your passphrase, it may save it to your keychain. Then, when you login later, it may bypass ssh-agent and retrieve it from your keychain. My official recommendation is just to not bother with passphrases.


Jan 30, 2023 9:05 AM in response to SausageSandwich

SausageSandwich wrote:

I've recently started using GitHub with ssh. I successfully generated my ssh keys, added them to my agent and stored the password in my keychain. Unfortunately, no matter what I try, I can't get my config file to load my ssh key back into my ssh agent when I reboot my Mac.

Can you clarify what you are talking about with respect to "my ssh agent"?


Are you able to login it other systems via ssh?


Can you describe exactly what you are trying?


3rd party sites often don't understand how the Mac works. I reviewed those Github instructions and they don't look correct. What they are describing seems much more complex than it should be. I wasn't using ssh with GitHub before. I just added my public key and it worked with no additional effort.

Feb 1, 2023 2:28 AM in response to etresoft

I am new to SSH, however my understanding is that after generating a passphrase protected SSH key, adding it to the mac's SSH Agent securely caches the decrypted private key and makes it available so that the user doesn't continually have to enter the keys passphrase. The agent used to do this automatically, but Apple changed things a couple of years back and now the keys have to be added to the agent manually after every reboot.

When I reboot my Mac the terminal command


Ssh-add -l


says the agent has no identities. If I try to connect to GitHub at this point then the connection fails.

The command


Ssh-add --apple-load-keychain


Adds the passphrase protected private key to my SSH Agent.


Ssh-add -l


confirms that the agent contains the key details. I can then seamlessly push and pull to and from GitHub and everything works fine until I restart my Mac.

My understanding is that the config file, formatted as per my message above, should automate this process so that the keys are automatically added to the agent without me having to do this manually. This is what the GitHub docs say, and I've seen it in a number of other places too.

My problem is that I can't get the config file to do this. I don't know whether I am doing something wrong, or whether I've misunderstood how the whole process is supposed to work.

Any help welcome.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Why won't my ssh/config file load my ssh keys into my ssh agent after reboot?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.