php空间配置ssh,PHP安装ssh2扩展

安装

下载包$ wget http://www.libssh2.org/download/libssh2-1.4.2.tar.gz $ wget http://pecl.php.net/get/ssh2-0.12.tgz

先安装 libssh2 再安装 SSH2$ tar -zxvf libssh2-1.4.2.tar.gz $ cd libssh2-1.4.2 $ ./configure --prefix=/usr/local/libssh2 $ make && make install

编译安装ssh2$ tar -zxvf ssh2-0.12.tgz $ cd ssh2-0.12 $ /usr/local/zend/bin/phpize $ ./configure --prefix=/usr/local/ssh2 --with-ssh2=/usr/local/libssh2 --with-php-config=/usr/local/zend/bin/php-config $ make && make install

修改php.ini 加入extension=ssh2.so

重启PHP

调试

用户名密码方式登录$user="root";//远程用户名 $pass="******";//远程密码 $connection=ssh2_connect('10.10.10.10',22); ssh2_auth_password($connection,$user,$pass);

用sshkey方式登录$connection=ssh2_connect('10.10.10.10',22); if(ssh2_auth_pubkey_file($connection, 'root', '/home/id_rsa.pub', '/home/id_rsa', 'secret')) { echo "Public Key Authentication Successful\n"; } else { die('Public Key Authentication Failed'); }

执行命令获取返回值$cmd="ps aux";//命令 $ret=ssh2_exec($connection,$cmd); stream_set_blocking($ret, true); echo (stream_get_contents($ret));

更多的PHP相关知识,请访问jquery中文网!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值