-
Notifications
You must be signed in to change notification settings - Fork 664
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
.shell command "su" loses interaction #661
Comments
Why not prefix your commands with 'sudo'? |
I been asking for an assignment in which I have to login as a root user instead of running commands with sudo due to that some commands it might take long to perform, but despite that, is this the correct path to perform what I'm aiming for ?, I mean... it is possible to execute command in a procedural way
|
UpdateI've managed to perform the "several commands" part in a more clean and readable way I think, (I know there are streams errors and end missing, but this is only for practical purposes). const Client = require('ssh2').Client;
const conn = new Client();
const encode = 'utf8';
const commands = [
'ls -a',
'su',
'rootP455word',
'uptime',
'cd /tmp && ls'
];
conn.on('ready', () => {
conn.shell(false, { pty: true }, (err, stream) => {
if (err) { console.log(err) }
stream.on('data', (data) => {
process.stdout.write(data.toString(encode));
});
commands.forEach((cmd) => {
stream.write(`${cmd}\n`);
});
});
})
.connect({
host: "192.168.100.100",
username: "username",
password: "usernamePassword"
}); |
Seems to work fairly well what you did! I came across a similar issue where the .exec command wouldn't su me in. I used your idea. Thanks! |
thanks to you @andrewgremlich and your reply, here also I made a workaround to perform the root change without loosing the interaction and executing some commands. stack overflow |
@FrancoAguilera thats a good post you shared! I didn't need to use it because my su command in this case isn't linked with a password, so all I needed was to just execute the su command. |
@FrancoAguilera per circumstance, do you know how to close the session? |
You could |
@mscdex thanks dude! I tried doing that, but it wouldn't work where I put it. So what I ended up doing is calling It worked then! Here is what I got...
|
I could login as root on a ssh connection like this :
but... how should I perform a second command (e.g. :$ touch /media/test_file.txt') once I'm on my root session, after the login is successful ?.
The text was updated successfully, but these errors were encountered: