0

I am developing an application using node.js(v8.1.4), express and angularjs. Node.js is installed in windows server 8 and I want to connect other windows servers using their respective credentials.

After connection is established, I want to execute commands on remote servers. But I do not know how to connect remote windows server or what package is available for windows connectivity.

For executing commands locally , I am using below code that is working fine,

var exec = require('child_process').exec;
var execcommand = 'dir';
var myproccess = exec(execcommand); 
myproccess.stdout.on('data', function(data) {
   console.log(data)
}

But I am not getting an idea how to connect remote windows with credentials and execute command.

Please help. I have been struggling with this for many days.

Thanks

2
  • I did not understand well I'm sorry... do you mean that you want to run the program with powershell or cmd? Commented Jun 11, 2018 at 13:17
  • 1
    Sorry my mistake. I want to run the program with CMD. Commented Jun 11, 2018 at 13:22

2 Answers 2

2

If you have SSH installed on each of the remote machines, you can execute a command in those servers by,

ssh <remote server ip or hostname> <command to execute>

However, you will need to setup the ssh keys in both machines in order to connect without password.

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

4 Comments

could you please guide me (or refer me any url) how to install ssh on windows server. I searched on net and it tells to install Putty. Is there any better way ?
Which version of Windows is installed on your servers? Windows 10 has a built-in SSH server and client which you can enable: bleepingcomputer.com/news/microsoft/… For other versions of Windows, check this guide: winscp.net/eng/docs/guide_windows_openssh_server
Thanks @Thimira. I tried follow 2nd url and install openssh on Windows 8.1 but it seems too complicated.could you please refer me some simple steps to install and check connectivity from putty.
Hi @Thimira, I have installed openshh through "setupssh-7.4p1-1.exe" and it is working. But the problem is , i am able to execute linux command like "ls" but not windows command like "dir". I wanted to execute windows command on remote windows machine through node.js. please suggest how is it possible to execute windows command in ssh shell. I am using "simple-ssh" npm package in my node scripts.
0

For the poor souls who have to work with Windows versions older than 10 (those who don't have built-in ssh servers), you can give PsExec a try. Some servers seem to come pre-installed with it. Here's the general syntax:

psexec.exe \\<address> <command>

Comments

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.