Remote shell execution in linux

Source: Internet
Author: User

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.

Related Article

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.