简体   繁体   中英

Run a process on Linux remotely from a Windows machine

I would like to be able to run a process that exists on a Linux machine remotely from a JAVA application running on a Windows machine. What is the best way to do this? Or an online resource that might be of help to me? Thanks very much.

You could use any of the many Java SSH client libraries, such as javassh , as long as the Linux machine runs an sshd (and the firewalls are all set to let ssh traffic through), which is likely to be the case. There are many possible ways to configure ssh authentication, basically boiling down to either sending password (securely) on the net, or using public/private key pairs (RSA or DSA) -- the latter is generally preferable, but you'll need to check with system and network administrators about this issue... it's not really a software development issue, but rather one related to system administration and security.

In short, use an ssh client.

Option 1: Install openssh package in Cygwin .

Option 2: Use Putty .

In either case, you can setup a keypair to allow for automatic (non-password) authentication.

You can use ssh command to login into a sytem example..

     String[] cm = {
                   "ssh",
                   "username@hostIP" ,
                   "your command"

                   };

     try
      {
       Process q=  Runtime.getRuntime().exec(cm);
       q.waitFor();
      }
    catch(Exception e) {}
  1. Expose the process as a [fire and forget] web service on the Linux machine.
  2. Call it from the windows machine.

You can also make a kind of client/server architecture. Your Java client will send a command to your Java server (~ webservice), that will execute the desired process. But obviously, it depends on your aims. Do you need to do that in a secure way? Is it through the internet or inside a local network? And finally, is the process a Java process?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM