linux遠程執行shell

來源:互聯網
上載者:User

linux遠程執行shell 第一種  www.2cto.com          java實現  易實現,易擴充(項目中使用)http://www.ganymed.ethz.ch/ssh2/ 官網 Java代碼  Connection conn = new Connection(ip);  boolean isAuthenticated = conn.authenticateWithPassword(username, password);  Session sess = conn.openSession();  sess.execCommand("ll");  InputStream stdout = new StreamGobbler(sess.getStdout());  BufferedReader br = new BufferedReader(new InputStreamReader(stdout));  System.out.println(sess.getExitStatus());  sess.close();  conn.close();    第二種  www.2cto.com          易實現,但是擴充比較麻煩.(平常的操作中,可以使用)192.168.168.45 執行 192.168.168.13 上的shell命令注意此過程不僅可以遠程遠程執行命令.任何遠程操作都無需再輸入密碼.原理是  ssh-keygen 和 ssh  www.2cto.com  1.產生45的密鑰,在45上執行Shell代碼  #ssh-keygen -t rsa  會在使用者的.ssh目錄下(/root/.ssh)產生id_dsa.pub 授權加密檔案2.13授權,把在45上產生id_dsa.pub 複製到13  的/root/.ssh下執行Shell代碼  #cat id_dsa.pub >> ~/.ssh/authorized_keys   3.設定13上檔案和目錄的許可權(保證.ssh和authorized_keys 的許可權是600)設定authorized_keysShell代碼  #chmod 600 authorized_keys  設定.ssh目錄Shell代碼  #chmod 600 -R .ssh  4. 執行遠程命令Shell代碼  ssh root@192.168.168.13 "sh /tmp/test.sh"   第三種        易實現不易擴充(而且,安全性需要自己維護)在apache/hdocs下放php指令碼.在php指令碼中執行shell命令. 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.