Linux – Windows 10 Linux subsystem ssh-agent not persisting added identities

ssh-agentwindows 10windows-subsystem-for-linux

I have started using my Windows 10 for Rails development and am using Linux subsystem for the same.

Recently I faced an issue connecting to a remote machine via SSH from the terminal. The public key is already available on the remote machine.

After doing some troubleshooting based on the resources I found on web I noticed that SSH agent was not running because ssh-add -l command didn't provided the expected output.

To make the SSH agent launch on startup I followed the instructions at https://github.com/abergs/ubuntuonwindows#2-start-an-bash-ssh-agent-on-launch and it worked flawlessly.

Now that SSH agent launches automatically I added my identity file to it using command ssh-add path/to/identity/file..

Note that while generating SSH keys I used custom file name id_work_gmail and id_work_gmail.pub. Thus I had to add it to the agent using above command.

After doing that I can successfully connect to remote machine through SSH.

Until this everything was going smooth. However as soon as I closed each of the Cmder Ubuntu Bash consoles and started a new one ssh-add -l informed The agent has no identities.. So again I had to add my custom-named identity file to the agent.

So this is something I need to do every-time I kill each of the Ubuntu Bash consoles and start a fresh one.

My question is how can we make the ssh-add path/to/identity/file/custom-named action persistent like it happens on actual Ubuntu machine. And am curious to know what is it that makes it a one-time activity on Ubuntu machine and a repeated activity on Windows 10 Linux Subsystem.

Thanks.

Best Answer

And am curious to know what is it that makes it a one-time activity on Ubuntu machine and a repeated activity on Windows 10 Linux Subsystem.

Normally, the ssh-agent runs in your session so it does not close earlier than you logout from your account in Linux.

If you use it from WLS and close the (probably) last window, it does reasonable cleanup and probably stops your ssh-agent, which is reasonable and safe to remove sensitive data from memory.

My question is how can we make the ssh-add path/to/identity/file/custom-named action persistent like it happens on actual Ubuntu machine.

Just do not close that window (or leave one opened on background ... it might help too). Or configure ssh to do that step automatically when you use the key for the first time. Just write to your ~/.ssh/config

Host server-you-are-connecting.to
  IdentityFile path/to/identity/file/custom-named
  AddKeysToAgent yes
Related Question