Open mark-veenstra opened 8 years ago
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!
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?
@casimirloeber This information needs to be in the README. That's ultra valuable.
For writes, the only option that's needed is agent
. The agentForward
option is useful for remote sessions.
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.
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 settingconfig.ssh.forward_agent = true
.If I manually SSH into the box:
vagrant ssh
. And once on the terminal inside the box do assh 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.