Skip to content

Instantly share code, notes, and snippets.

@jiggneshhgohel
Last active September 8, 2022 00:28
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jiggneshhgohel/afe96f0d57bdbf8beba305a73905402d to your computer and use it in GitHub Desktop.
Save jiggneshhgohel/afe96f0d57bdbf8beba305a73905402d to your computer and use it in GitHub Desktop.
Windows 10 Linux Subsystem SSH-agent issues
Host github.com-jiggneshhgohel
HostName github.com
User git
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_work_gmail
AddKeysToAgent yes


Host csexperimental.abc.com
IdentityFile ~/.ssh/id_work_gmail
AddKeysToAgent yes

References:

FROM

$ ssh -V
OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.8, OpenSSL 1.0.1f 6 Jan 2014

TO

~$ ssh -V
OpenSSH_7.3p1 Ubuntu-1, OpenSSL 1.0.2g  1 Mar 2016
@jiggneshhgohel
Copy link
Author

jiggneshhgohel commented Aug 8, 2017

After adding the option AddKeysToAgent yes in ~/.ssh/config and adding the key to agent first time it worked as can be seen in the output below:

~$ ssh-add .ssh/id_work_gmail
Identity added: .ssh/id_work_gmail (.ssh/id_work_gmail)
MyMachine:~$ ssh -T git@github.com
setsockopt IPV6_TCLASS 8: Operation not permitted:
Hi jiggneshhgohel! You've successfully authenticated, but GitHub does not provide shell access.

@jiggneshhgohel
Copy link
Author

jiggneshhgohel commented Aug 8, 2017

Howeve after existing the Bash session (the last console window) and logging-in again I get to the same position of requiring to re-add the keys to ssh agent using ssh-add command. Please refer the output below:

Initializing new SSH agent...
MyMachine:~$ ssh -T git@github.com
Permission denied (publickey).
MyMachine:~$ ssh-add -l
The agent has no identities.

If this has to go this way then there is no need to use a SSH config file. Adding the key once using ssh-add command makes the key to be used throughout the bash session until I exit the last console.

@jiggneshhgohel
Copy link
Author

:~$ ssh-add .ssh/id_work_gmail
Identity added: .ssh/id_work_gmail (.ssh/id_work_gmail)
MyMachine:~$ ssh deployer@csexperimental.abc.com
setsockopt IPV6_TCLASS 16: Operation not permitted:
Welcome to Ubuntu 16.04.3 LTS (GNU/Linux 4.4.0-36-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

7 packages can be updated.
7 updates are security updates.


Last login: Tue Aug  8 07:18:31 2017 from xx.xx.xxx.xxx
deployer@experimental:~$

Then exited from remote server.

Then exited the bash session on my machine.

Then opened a new bash session.

Initializing new SSH agent...
MyMachine:~$ ssh deployer@csexperimental.abc.com
setsockopt IPV6_TCLASS 16: Operation not permitted:
Welcome to Ubuntu 16.04.3 LTS (GNU/Linux 4.4.0-36-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

7 packages can be updated.
7 updates are security updates.


Last login: Tue Aug  8 07:40:01 2017 from 106.77.126.214
deployer@experimental:~$

So it works for host csexperimental.abc.com i.e. using the AddKeysToAgent yes option in .ssh/config the SSH keys are persisted and they don't need to be re-added using ssh-add every time I start a fresh bash session.

@jiggneshhgohel
Copy link
Author

jiggneshhgohel commented Aug 8, 2017

Also it works too for the configured Github account!

~$ ssh github.com-jiggneshhgohel
setsockopt IPV6_TCLASS 16: Operation not permitted:
PTY allocation request failed on channel 0
Hi jiggneshhgohel! You've successfully authenticated, but GitHub does not provide shell access.
Connection to github.com closed.

@jiggneshhgohel
Copy link
Author

THANKS TO jakuje FOR HIS PROMPT ASSISTANCE ON RESOLVING THIS.

@Choongkyu
Copy link

I was wondering which of the links you've included lead to the solution for having the keys in the config file get added to the ssh-agent on loading bash for wsl. I've tried adding the line AddKeysToAgent yes to no avail. On load, I find that I get prompted for the passphrase for id_rsa, but I still need to manually type ssh-add gitKey before the proper private key is added to my ssh-agent. Thanks for documenting your progress, btw.

@jiggneshhgohel
Copy link
Author

@zebralight You should follow the steps listed in answer https://stackoverflow.com/a/45562886/936494 and you should be through.

Hope that helps.

@o-be-one
Copy link

o-be-one commented Oct 6, 2017

Thanks a lot for your last link jiggnesh, it helped me to deal with it :).

@bahamas10
Copy link

bahamas10 commented Oct 18, 2017

I tried all of the solutions in this gist and the links provided but kept running into issues - mainly around my keys requiring passphrases so they can't be automatically added (without manual intervention). I wrote a post here http://daveeddy.com/2017/10/18/persistent-sshagent-on-bash-on-ubuntu-on-windows/ about how I solved the issue.

Long story short, I create a Windows login service that starts a hidden instance of bash that runs ssh-agent to keep it running so long as the computer is up. When you add a key to the agent (with or without a passphrase), it will stay in the agent and the agent will stay up so long as your user is logged into Windows.

All of the code for the scripts is on GitHub as well available under an open source license: https://github.com/bahamas10/windows-bash-ssh-agent

@ralphie02
Copy link

ralphie02 commented Jan 4, 2018

@jiggneshhgohel is this persistent on a workstation reboot?

@jiggneshhgohel
Copy link
Author

is this persistent on a workstation reboot?

@ralphie02 By explicitly stating workstation if you are referring to something special then sorry I cannot comment on it. But after doing the config shown in above steps and rebooting the machine the config is persistent.

@gomker
Copy link

gomker commented Jul 5, 2018

This method was not working for me with latest Ubuntu 18.04 and Windows 10
Errors connecting to SSH agent still occur

FYI - looks to be a bug

microsoft/WSL#3183

@ygale
Copy link

ygale commented Aug 30, 2018

According to the discussion in microsoft/WSL#3183, the issue with ssh-agent on Ubuntu 18.04 is fixed in insiders build 17704. The fix will be pushed out to regular Windows builds as part of the Fall 2018 update. In the meantime, one reported work-around is to retrieve the ssh-agent binary for Ubuntu 16.04 from the Ubuntu site and use that on 18.04 for now. In #3183 there is a recipe by @rcarmo how to do that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment