Search code examples
javawindowssshremote-desktopwindows-shell

Java to Control a Windows Server


As we know Java can send SSH command to a Linux server by jsch or sshj. Is it possible to do same thing to a Windows server, by remote desktop protocol (on port 3389) or other way?


Solution

  • From your description I guess the issue is less about Java itself but about the choice of remote control in the first place.

    ssh is a textual protocol, connecting a terminal on the client to a login session / shell on the server so that the shell will use the terminal on the client for its default stdin / stdout / stderr. Unless you use ssh -X, in which case ssh will in addition to that establish a tunnel for the X-protocol. This means that ssh is primarily a means of textual remote control.

    As far as I am aware, RDP - Remote Desktop Protocol is primarily a means of graphical remote control, making automation really difficult as compared to textual remote control.

    So, it pretty much depends on whether you want textual / command control or graphical control, and they are very very different from each other.

    The best and most convenient way known to me to turn a Windows machine into something that can be remote controlled textually in a controlled and reasonably fashion, mostly for the purposes of automation, is to install Cygwin with sshd and setup sshd as a service. Then you can use the same client libraries regardless of whether your server is running on Linux / UNIX / Mac OS X or Windows.

    telnet and rlogin would also be possible, but I would not recommend those because of their lack of encryption - everyone with access to the network could obtain the login credentials by simple eavesdropping.

    If you want to use graphical remote control, you could use RDP or X11, to name just two. You can get X11 running on Windows by setting up Cygwin xdm running as a service on the Windows machine to use XDMCP - X Display Manager Control Protocol. There are also services available for Linux that provide RDP, in case you choose RDP and want the same protocol for all servers.