cmderdev / cmder

Lovely console emulator package for Windows
https://cmder.app
MIT License
25.92k stars 2.03k forks source link

How to enable ssh-agent? #193

Closed CaseyLabs closed 9 years ago

CaseyLabs commented 10 years ago

I'm trying to setup Cmder to use ssh-agent forwarding:

λ ssh-agent SSH_AUTH_SOCK=/tmp/ssh-JqBCMa6092/agent.6092; export SSH_AUTH_SOCK; SSH_AGENT_PID=7840; export SSH_AGENT_PID; echo Agent pid 7840;

λ ssh-add my-public-key.pub Could not open a connection to your authentication agent

Any ideas what I'm doing wrong here?

Thank!

ccoenen commented 10 years ago

same problem here, if someone is using this without problems i would appreciate a hint on how to set it up.

bojanrajkovic commented 10 years ago

I came up with this gist, which does the trick: https://gist.github.com/bojanrajkovic/6997145eda613467ace4. You can add this to init.bat. I'd love some input from @bliker or someone else as to how to get this to run on "startup" without being overwritten by Cmder upgrades.

ccoenen commented 10 years ago

Sweeet! Works as advetised :-)

I would even go as far as making this an official option (perhaps not default, but an option nonetheless!)

Shoozza commented 10 years ago

I wrote another solution for the problem which doesn't run ssh-agent for each new Cmder instance.

It works without temporary files, only runs ssh-agent when it isn't running and adds ssh keys in %HOME%.ssh*_rsa if they were not yet added.

https://gist.github.com/Shoozza/8fe8b0c85fa89cd3b1c4

bojanrajkovic commented 10 years ago

Nice, that's much better than my hack. I've switched to Powershell + posh-git in the meantime (which has built-in support for ssh-agent), but this is a cool solution.

ogrim commented 10 years ago

Using the script from @bojanrajkovic it works for me. With @Shoozza's fix I only get: "Could not open a connection to your authentication agent". Strange, I don't see why the call to ssh-add shouldn't work in the second script as well.

rmorrin commented 10 years ago

I get the same with @Shoozza 's fix also: Could not open a connection to your authentication agent. Would be nice to resolve as it's a cleaner workaround for this issue.

Shoozza commented 10 years ago

Rewrote the script to handle the issue (revision 7). The problem was that another ssh-agent was running already and didn't use the /tmp/ssh-agent.sock. @ogrim @rmorrin

ogrim commented 10 years ago

Thanks, @Shoozza. It's working fine for me now :+1:

rmorrin commented 10 years ago

@ogrim Same for me - thanks @Shoozza! Is there a way to automatically run this each time a new Cmder window/tab is opened?

ogrim commented 10 years ago

You can add it to cmder/vendor/init.bat. I have the script on my path as agent.cmd, so I have only added call agent as the last line in init.bat

Shoozza commented 10 years ago

I added @call "%CMDER_ROOT%/vendor/agent.cmd" at the end of cmder/vendor/init.bat.

rmorrin commented 10 years ago

@ogrim @Shoozza Thanks, exactly what I was looking for! This has been a huge headache for me with Cmder for a long time - you should definitely submit a PR :+1:

lokifer commented 9 years ago

@Shoozza Cheers, this is fantastic.

RDeluxe commented 9 years ago

This need to be added to the repo !

ccoenen commented 9 years ago

I'm taking the liberty of notifying @bliker directly. I hope he doesn't mind. This shoud be part of cmder for sure :D

MartiUK commented 9 years ago

If someone adds a pull request to add the file there shouldn't be a problem.

ogrim commented 9 years ago

I went ahead and made pull request #351, thanks everyone!

teleivo commented 9 years ago

Based on your great solution, a script which loads keys into putty's pageant. https://gist.github.com/teleivo/2eb7dd6afbda414c9269

Same as above add @call "%CMDER_ROOT%/vendor/pageant_autostart.cmd" at the end of cmder/vendor/init.bat

pageant helps those who want to use vagrant on windows with puppets vcsrepo to clone private git repos: https://github.com/mitchellh/vagrant/issues/1735

thanks a lot for cmder :)

cdelgehier commented 9 years ago

It is working for me but the agent forwarding is not good How to export SOCK and PID variable?

cdelgehier commented 9 years ago

With your script @teleivo and http://niki.hammler.net/wiki/PuttyAgent_now_supports_openssh/cygwin/msys I am a satisfied man

IrNoThnk commented 9 years ago

has anyone successfully had confirmation with ssh-add working?

ssh-add -c /path/to/key

Adding is no problem, but you'll get a failure when connecting because there is no /usr/libexec/ssh-askpass. At least that's the issue that I've had in Ubuntu before.

isdsc commented 9 years ago

I am currently using start-ssh-agent script provided by msysgit to set up my ssh-agent in cmder (it is in the default cmder search path: %git_install_root%\cmd). Is there any reason to switch to the one added to the development branch?

LondonAppDev commented 9 years ago

@isdsc any idea how to make it enable agent forwarding?

isdsc commented 9 years ago

@markwint if the question is how start-ssh-agent works with agent forwarding, the answer is (AFAIK):

It just starts ssh-agent properly in your session [in Windows console] and adds the default identity, it doesn't deal with agent forwarding.

Here is my ssh configuration:

λ head ~/.ssh/config
# Shortcut to connect to my server
Host mysvc
 User MyName
 IdentityFile ~/.ssh/id_rsa
 HostName myservice.example.com

# GitHub account: isdsc
Host github.com
 IdentityFile ~/.ssh/isdsc
 HostName github.com

Here is how I use agent forwarding with a second identity to connect to GitHub. See GitHub for details.

λ start-ssh-agent
Removing old ssh-agent sockets
Starting ssh-agent: done
Enter passphrase for /c/Users/MyName/.ssh/id_rsa:
Identity added: /c/Users/MyName/.ssh/id_rsa (/c/Users/MyName/.ssh/id_rsa)

λ ssh-add ~/.ssh/isdsc
Enter passphrase for /c/Users/MyName/.ssh/isdsc:
Identity added: /c/Users/MyName/.ssh/isdsc (/c/Users/MyName/.ssh/isdsc)

λ ssh -T git@github.com
Hi isdsc! You've successfully authenticated, but GitHub does not provide shell access.

However, just to make sure I understood what agent forwarding means, I googled it and found another explanation: http://www.unixwiz.net/techtips/ssh-agent-forwarding.html#fwd

If your question is about this second interpretation, I don't know how to respond to your question because:

  1. I don't know the specifics of your situation.
  2. I don't think I have used ssh in that way (unless that's what's going on behind the scenes when I connect to GitHub).
airtonix commented 9 years ago

@isdsc regarding 2. no. it is not. if you've never chained ssh tunnels together then you've never used agent-forwarding.

SpacemanPete commented 9 years ago

@teleivo, your option seems to be the one that would fit my eneeds best, but I get an error that >'pageant' is not recognized as an internal or external command, operable program or batch file.<

even though the %PATH% has my "C:\Users.ssh" location listed in there...

I edited the pageant_autostart.cmd file to list the full explicit path to pageant.exe and it works but i'm puzzled why cmder can't find pageant...

OleksiiShevchenko commented 8 years ago

Thanks, works great!

ilan-schemoul commented 6 years ago

For futur people the equivalent to linux's eval seems to be call so to call ssh-agent it would be call %GIT_INSTALL_ROOT%/cmd/start-ssh-agent.cmd

jocafi commented 1 year ago

I noticed that I had to start the Windows service "OpenSSH Authentication Agent". I think this advice may help some solution here to work, specially the solution from @bojanrajkovic . In my case, after putting his Gist in the CMder settings, I had only to execute the command "ssh-add.exe" in the CLI. If I add optional arguments like "ssh-add.exe %HOME%.ssh\id_ed25519" , it does not work.

Mooninaut commented 1 year ago

The latest version of start-ssh-agent.cmd seems to open a cmd shell with the arguments provided to it on the command line, which was giving me a shell with no Cmder magic. I changed my default {cmd::Cmder} task to run "C:\Program Files\Git\cmd\start-ssh-agent.cmd" /k ""%ConEmuDir%\..\init.bat" " and that worked for me.

renandecarlo commented 3 months ago

For some reason either ssh-agent or ssh-pageant is working for me. It asks for password on startup, but then it asks again when I ssh to a server.