teambition / gulp-ssh

SSH and SFTP tasks for gulp
184 stars 38 forks source link

Error: Encrypted private key detected, but no passphrase given #43

Closed stefanwalther closed 8 years ago

stefanwalther commented 8 years ago

When using the following code and using a passphrase protected key, I get the error:

Error: Encrypted private key detected, but no passphrase given

Code:

'use strict';
var gulp = require( 'gulp' );
var debug = require('gulp-debug');
var path = require('path');
var fs = require('fs');
var GulpSSH = require('gulp-ssh');
var expandTilde = require('expand-tilde');

var configKey = {
    host: '10.0.0.222',
    port: 22,
    username: 'myuser',
    privateKey: fs.readFileSync( expandTilde('~/.ssh/id_rsa'))
};

var gulpSSHKey = new GulpSSH({
    ignoreErrors: false,
    sshConfig: configKey
});

//Todo: Throws an error: "Error: Encrypted private key detected, but no passphrase given"
gulp.task('ssh:key', function () {
    return gulp
        .src(paths.src)
        .pipe(gulpSSHKey.dest('/cygdrive/c/Users/myuser/bla'));
});

Any ideas how to fix that?

Regards Stefan

zensh commented 8 years ago

Please make sure your id_rsa correct

howells commented 8 years ago

I have this issue too - I'm unsure how to provide the passphrase required for the encrypted key?

jzp74 commented 8 years ago

I had the same issue: You have to add a passphrase to the config, like this

var configKey = {
    host: '10.0.0.222',
    port: 22,
    username: 'myuser',
    privateKey: fs.readFileSync( expandTilde('~/.ssh/id_rsa'))
    passphrase: 'your_passphrase_here'
};
pavelsl commented 7 years ago

It would be cool if author will add this to description page.

daveobike commented 7 years ago

It's interesting that I do not need to supply a passphrase using gulp-rsync (for the same credentials and same gulp file) or from the command line running ssh manually (nor do I need to explicity indicate the keyfile). Once I have a shell that is successfully logged in with destination X and supplied passphrase, I never seem to need to enter it again for subsequent SSH sessions. I assume the passphrase has been associated with the key somehow. Is there a way to have gulp-ssh exhibit the same behavior as I experience from gulp-rsync and command line ssh? If I have to supply the passphrase each time, maybe allow for command line interaction like Fabric or others? I do not want to store my passphrase in the clear or in a separate file

daveobike commented 7 years ago

For anyone coming to this issue, I was able to achieve my traditional bash ssh-agent based login experience with gulp-ssh. After reviewing, gulp-ssh is just using SSH2. Reviewing the SSH2 docs there is a config parameter, agent, that can point to the ssh-agent socket and provide auto login with ssh identity and cached key passphrase. Steps:

  1. Delete and do not use the the gulp-ssh config parameter, privateKey, (ssh2 will prioritize this config and will fail out on the lack of passphrase for private key)
  2. If you don't know your local ssh-agent socket file location, type the following at the command line: echo "$SSH_AUTH_SOCK" (if this doesn't show up you probably don't have ssh-agent setup)
  3. replace the privateKey key parameter in the gulp-ssh config object with the agent key: var config = { ... username: xxx, agent: '<the results of echo $SSH_AUTH_SOCK>', ... };
Cristy94 commented 6 years ago

@daveobike How can I get the SSH_AUTH_SOCK variable on Windows while using Pageant?