sudo apt-get install libssh2-1-dev sudo pecl install channel://pecl.php.net/ssh2-0.12 echo 'extension=ssh2.so' | sudo tee /etc/php5/cli/conf.d/50-ssh2.ini
帳號密碼訪問服務器方式:php
<?php $user = "***"; $pass = "***"; // 鏈接服務器 $connection = ssh2_connect(服務器IP, 服務器端口); if ( ! $connection) die('Connection failed'); // 用戶驗證 $ret = ssh2_auth_password($connection, $user, $pass); if ( ! $ret) { die('ssh auth fail'); } $cmd = "df -h"; // 執行命令行 $stream = ssh2_exec($connection, $cmd); // 輸出執行結果 stream_set_blocking($stream, true); $cmd = fread($stream, 4096); echo $cmd;