teambition / gulp-ssh

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

"Error: Cannot parse privateKey: Unsupported key format" when using id_rsa file #26

Closed prometheas closed 9 years ago

prometheas commented 9 years ago

Hey there. I'm having a devil of a time getting gulp-ssh to use my ssh keys; hoping to either get the problem fixed or (perhaps more likely) be educated as to whether I'm maybe doing something bone-headed… but here's the deal.

I've got these RSA ssh keys (generated using ssh-keygen with a passphrase), and I keep them in ~/.ssh, like any civilized human being might. (Perms on those files are right, just to preempt that particular question — I've been using these keys for the better part of a year to breeze around into various hosts.)

The trouble is that whenever I point gulp-ssh to my private key and attempt to access a remote host that I routinely access successfully via cli ssh, I get the following error:

Error: Cannot parse privateKey: Unsupported key format
    at Client.connect (/vagrant/node_modules/gulp-ssh/node_modules/ssh2/lib/client.js:147:13)
    at GulpSSH.connect (/vagrant/node_modules/gulp-ssh/index.js:79:15)
    at GulpSSH.exec (/vagrant/node_modules/gulp-ssh/index.js:110:8)
    # then it's my code, followed by node

I don't usually cut my code out, but here's my file:

var GulpSSH = require('gulp-ssh');

var sshConfig = {
  host: 'redacted', // redacted this for obvious reasons :)
  port: 22,
  username: 'yanni',
  privateKey: '/home/yanni/id_rsa'
};

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

ssh.exec('touch ~/my-ssh-test.txt');
ssh.close();
prometheas commented 9 years ago

Gah, just realized that you need the private key text itself; not merely a path to a key file. I've submitted a PR for ssh2 which could address this use case.

Closing this issue on this project.

williansmartins commented 7 years ago

I'm having the same problem, but I'm setting the complete path and the error persistis

loicbisiere commented 5 years ago

Hi, I got the same error message for the new SSH key format. Like to problem explain in this comment: https://github.com/mscdex/ssh2-streams/issues/100#issue-309317656

I needed to convert my key into old format to fix the problem. New format start : "-----BEGIN OPENSSH PRIVATE KEY-----" Old format start: "-----BEGIN RSA PRIVATE KEY-----"

slash851 commented 1 year ago

only solution that worked for me was to change to sftp extension instead. No need for converting the file nor generating new one. https://marketplace.visualstudio.com/items?itemName=Natizyskunk.sftp