Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Howto use in combination with a ssh-agent? #55

Open
mark-veenstra opened this issue Sep 2, 2016 · 5 comments
Open

Howto use in combination with a ssh-agent? #55

mark-veenstra opened this issue Sep 2, 2016 · 5 comments

Comments

@mark-veenstra
Copy link

I am using gulp-ssh within my gulpfile.js which is located inside a Vagrant box.
I have enabled SSH forwarding agent to this box with the setting config.ssh.forward_agent = true.

If I manually SSH into the box: vagrant ssh. And once on the terminal inside the box do a ssh myuser@myotherhost I get connected without a password prompt. So far so good.

But how can I configure Gulp-SSH to make use of this forwarded private key also? Because I can't configure the password in gulp-ssh and also I can't configure the private key, since it is not available inside the vagrant box.

Any ideas/help is welcome.

@casimirloeber
Copy link

I signed up for GitHub in 2013 and have literally never logged in since but I struggled with this exact issue for long enough that I dusted off my login details to hopefully save you some pain.

gulp-ssh uses the ssh2 (https://github.com/mscdex/ssh2) node module for handling the actual SSh connections. And ssh2 has a variety of additional connection options including the 2 we need to get this working: agent and agentForward which you can find listed here:

https://github.com/mscdex/ssh2#client-methods

Agent forwarding works using a socket which is conveniently available under the environment variable SSH_AUTH_SOCK which you can access using process.env.SSH_AUTH_SOCK.

So to put this all together.. your sshConfig hash would look like:

sshConfig: {
            host: 'xxx.xxx.xxx.xxx',
            username: 'gandalf',
            agent: process.env.SSH_AUTH_SOCK,
            agentForward: true
    }

Hope this helps!

@daveobike
Copy link

I unfortunately had to discover this myself, having overlooked this response. One minor obvservation, I do not have to set agentForward: true. And I do not have it setup in my local ssh setup. I thought that agentForward forwarded all key identities as opposed to the identity tied to the public key on the server side?

@mojavelinux
Copy link
Contributor

@casimirloeber This information needs to be in the README. That's ultra valuable.

@mojavelinux
Copy link
Contributor

For writes, the only option that's needed is agent. The agentForward option is useful for remote sessions.

@mojavelinux
Copy link
Contributor

mojavelinux commented Feb 12, 2018

There is now a test for this and it's documented in the README.

You can also set useAgent to true it it will automatically use process.env.SSH_AUTH_SOCK.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants