Linux Remote shell execution of the first www.2cto.com java Implementation is easy to implement, easy to expand (used in the project) http://www.ganymed.ethz.ch/ssh2/ official website Java code Connection conn = new Connection (ip); boolean isAuthenticated = conn. authenticateWithPassword (username, password); Session sess = conn. openSession (); sess.exe cCommand ("ll"); InputStream stdout = new StreamGobbler (sess. getStdout (); BufferedReader br = new BufferedReader (new InputStreamReader (stdout); Sy Stem. out. println (sess. getExitStatus (); sess. close (); conn. close (); the second type of www.2cto.com is easy to implement, but it is troublesome to expand. (this can be used in common operations) run the shell command on 192.168.168.13 at 192.168.168.45. Note that this process can not only be remotely executed. no Password is required for any remote operation. the principle is ssh-keygen and ssh www.2cto.com 1. generate a secret of 45, and execute Shell code # ssh-keygen-t rsa will be in the user's. under the ssh directory (/root /. ssh) generate id_dsa.pub authorization Encryption File 2.13 authorization, copy the id_dsa.pub generated on 45 to/root /. run the Shell code in ssh # cat id_dsa.pub> ~ /. Ssh/authorized_keys 3. set the permissions for files and directories on Oct 13 (ensure that. the permissions for ssh and authorized_keys are 600) set authorized_keysShell Code # chmod 600 authorized_keys settings. shell code # chmod 600-R. ssh 4. execute remote command Shell code ssh root@192.168.168.13 "sh/tmp/test. sh "the third method is easy to implement and not easy to scale (and the security needs to be maintained by yourself). In apache/hdocs, place php scripts. run the shell command in the php script.