Sudo commands and changing directories
simon-p-r opened this issue · comments
Hi
I can't seem to change directories within continuous mode, also I can't use sudo commands because of no tty. I tried passing 'pty' is true within options. See code below;
var sequest = require('sequest');
var Fs = require('fs');
// Setup the host to connect to
var host = 'user@hostname';
var options = {
username: 'user',
privateKey: Fs.readFileSync(sshKey)
// pty: true
}
// Create the connection
var conn = sequest.connect(host, options);
// Get the sequest object back for streaming and error handling
var seq = conn();
// Pipe output to the terminal, substitute for whatever stream you want
// or remove completely if you don't need it
seq.pipe(process.stdout);
seq.on('error', function (err) {
// Error handler goes here
throw err;
});
// Do some stuff
seq.write('cd /some/path');
seq.write('sudo su');
seq.write('ls -la');
seq.write('cd /some/other/paths');
seq.write('ls -la');
// All done
seq.end();
Any help would be greatly appreciated!
I ran into the same issue. I believe it is because the sequest is calling the exec function of the underlying ssh2 connection. ssh2 also provides a shell function, which I think has the functionality you're looking for.
This seems like it could totally be an option. Would it make sense for both of you if the shell command was used when pty: true
or something similar was passed in? Also feel free to submit a PR :)
Unfortunately the problem isn't as simple as passing JS pty:true
option as to write a sudo password after command you must detect changes in prompt.
This module https://github.com/cmp-202/ssh2shell does this however it is written in coffeescript, so I will try to make a PR including some of this logic. I am an extreme novice so bear with me.
Currently it appears the exec and sftp native functions are wrapped by sequest would it be best if I wrapped the 'shell' function like this?
Finally the excellent ssh2 module has bumped to version 0.4.x which I would try to include in PR.