Windows 10 Linux subsystem ssh-agent not persisting added identities

8,698

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
Share:
8,698
Jignesh Gohel
Author by

Jignesh Gohel

I am Jignesh Gohel, a Senior Software Developer having 15 years of experience in developing and delivering commercial software in diverse domains. Following keywords describe me and my work in the best possible manner: Highly Experienced Professional Proactive Reliable Committed Focused Determined to deliver quality solutions I have expertise in designing, developing and delivering web-applications meeting the customers expectations and helping them gain increase in productivity using the solution delivered.

Updated on September 18, 2022

Comments

  • Jignesh Gohel
    Jignesh Gohel almost 2 years

    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.

  • Jignesh Gohel
    Jignesh Gohel almost 7 years
    Thanks for the elaborate answer. Your suggestion of using option AddIdentityToAgent yes resulted in Bad configuration option: addidentitytoagent. I referred the manual at linux.die.net/man/5/ssh_config and there I could not find that option in supported options and hence I guess this error.
  • Jakuje
    Jakuje almost 7 years
    Sorry. I meant AddKeysToAgent inestead.
  • Jignesh Gohel
    Jignesh Gohel almost 7 years
    same error Bad configuration option: addkeystoagent
  • Jakuje
    Jakuje almost 7 years
    Then you have old OpenSSH (it works with 7.2 and newer), so either update or go with the first option.
  • Jignesh Gohel
    Jignesh Gohel almost 7 years
    Thanks I will try to update it. BTW I also found a related SO Post unix.stackexchange.com/a/269132/146438 on that option.
  • Jignesh Gohel
    Jignesh Gohel almost 7 years
    I updated the SSH on my WLS however using your suggestion to use a config file and add AddKeysToAgent option to it is not proving to be helpful in the original problem I have i.e. after exiting the last session and logging-in again I have to re-add key using ssh-add. I have documented this in a gist gist.github.com/jiggneshhgohel/afe96f0d57bdbf8beba305a739054‌​02d.
  • Jakuje
    Jakuje almost 7 years
    Your comments show that you are connecting to github.com and not the hosts you defined the option for and therefore it is not applied.
  • Jignesh Gohel
    Jignesh Gohel almost 7 years
    Thanks. You are right. I have added new comments in the gist showing that the issue is resolved.