almarc
almarc

Reputation: 1658

Node simple-ssh exiting without errors

I'm trying to connect to an Ubuntu EC2 machine using the Node simple-ssh library.

The code:

const SSH = require('simple-ssh')
const fs = require('fs')

var ssh = new SSH({
    host: 'my-hostname',
    user: 'ubuntu',
    pass: fs.readFileSync("key.pem")
});

ssh.exec('echo $PATH', {
    out: function(stdout) {
        console.log(stdout)
    }
}).start()

When I run node app.js, it doesn't output anything. Nor there are any signs of it actually being connected to the machine. It runs for 2-3 seconds and then exits without errors.

Also, I tried entering a random key as the pass. And that makes the program run much quicker, which is a sign that the wrong key fails immediately, while the correct one gets somewhere before exiting. But the exec command doesn't seem to run. I tried to mkdir and the directory didn't appear.

The credentials are 100% correct, I'm able to SSH to the machine via Putty using it.

Upvotes: 1

Views: 968

Answers (1)

Eric Wong
Eric Wong

Reputation: 1463

Read the manual.

config.host { String }: Hostname

config.port { Number }: Port number (default: 22)

config.user { String }: Username

config.pass { String }: Password

config.timeout { Number }: Connection timeout in milliseconds (default: 10000)

config.key { String }: SSH key

config.passphrase { String }: Passphrase

You should use key instead of pass

Upvotes: 1

Related Questions