Remote shell execution in linux: The first implementation of www.2cto. comjava is easy to implement and easy to expand (used in projects) http://www.ganymed.ethz.ch/ssh2/ Official website Java code ConnectionconnnewConnection (ip); booleanisAuthenticat... linux remote execution of shell first class www.2cto.com java implementation is easy to implement, easy to expand (used in projects) 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); System. out. println (sess. getExitStatus (); sess. close (); conn. close (); the second type is www.2cto.com Implementation, but the expansion is troublesome. (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.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service