0

Folks! I got the following error when I'm trying run my cmds with remote-exec https://www.npmjs.com/package/remote-exec.

Error: Unable to parse private key while generating public key (expected sequence)

Anyone know why? Thankyou!

My Code:

controller.mySync = function(req, res) {

    // remote-exec
    var connection_options = {
        port: 22,
        username: 'user',
        privateKey: require('fs').readFileSync('/home/host/.ssh/id_rsa'),
        passphrase: 'mypws'     
    }

    var hosts = [
        '192.168.1.1'
    ];

    var cmds = [
        'ls -l',
        'cat /etc/hosts'
    ];

    rexec(hosts, cmds, connection_options, function(err, stdout, stderr){
        if (err) {
            console.log(err);
            res.status(500).json(err);
        } else {
            console.log('Great Success!!');
            res.status(200).json(stdout);
        }
    });

};
halfer
  • 19,824
  • 17
  • 99
  • 186

1 Answers1

1

(Posted solution on behalf of the OP).

I solved my problem. What did I do?

Initially it was necessary to enter the 'passphrase' that was empty, and that generated the error. But even informing the password, it generates a new error:

[Error: Authentication failure. Available authentication methods: publickey,password] level: 'authentication', partial: false }

In this case, I begotten again a public/private rsa key pair with my host user:

$ ssh-keygen -t rsa -b 4096 -C "myuser"

After generating your key pair, missing the final drive, which installs the public key on the host, allowing it to be used for authentication:

$ ssh-copy-id -i ~/.ssh/id_rsa.pub login@host
halfer
  • 19,824
  • 17
  • 99
  • 186
  • @RobsonFagundes: the purpose of the first sentence is to indicate that I am not the author of this material. It was added as an addendum to the question, and it should have been an answer - I posted it for the OP. – halfer Nov 21 '16 at 11:31