0

Is there a way to launch process (bash) from node.js under specific user when knowing linux username and password of this user.

I want to transfer terminal from server over socket.io to web browser and I need every user to act under their usernames, so user permissions are acting like on proper ssh.

1 Answer 1

1

Basically you are sharing an SSH connection over the web.

You should spawn child processes from node.js inbuilt functionality child_process.spawn like the following:

var spawn = require('child_process').spawn; ls = spawn('ls', ['-lh', '/usr']);

see here: http://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options

To initiate each users SSH you should use :(in the child process spawn)

ssh -tt [email protected] [command_to_execute]

Rest is upto you to link the child process on node.js with the interface on webpage with your socket.io.js

Sign up to request clarification or add additional context in comments.

4 Comments

So I actualy need to ssh to local machine and send output through https? There is no way to cut the ssh from it on local machine?
SSH access has to be restricted node.js server without exposing critical details to the user. To get output, the spawned ssh process has stdout and stderr streams which you can capture and send using socket.io, see here nodejs.org/api/child_process.html#child_process_child_stdout
What about using telnet when I connect to shell on the same machine where is node server without losing security.
For testing on local, its OK. I would prefer SSH though, telnet is not secure and has been replaced by SSH.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.