ps aux | grep lighttp 查看web server的用户名是谁

 

登录lighttpd的用户名,运行ssh-keygen有啥提问的话基本都是回车就行

生成的公匙在~/.ssh/id_rsa.pub

 

然后登录到远程机器运行:cat id_rsa.pub >> ~/.ssh/authorized_keys

 

这样在本地机器中不需要密码就可以ssh到远程机器,如:ssh 210.76.114.251

 

PHP两种调用ssh的方法

1.用key方式
$connection=ssh2_connect('210.76.114.251',22);

if(ssh2_auth_pubkey_file($connection, 'root',

                          '/root/.ssh/id_rsa.pub',

                          '/root/.ssh/id_rsa', 'secret')) {

  echo "Public Key Authentication Successful\n";

} else {

  die('Public Key Authentication Failed');

}

 

2.用密码方式

$connection=ssh2_connect('210.76.114.251',22);

if (!$connection) die('Connection failed');

$flag=ssh2_auth_password($connection,'username',’password');

var_dump($flag);

//$cmd="/data/script/start.sh knowledgelib_fix_2";

//$ssh2_exec($connection,$cmd);

 

 

在Ubuntu下安装PHP的ssh2扩展

在Ubuntu 10.04下安装不需要任何编译了

 

apt-get install libssh2-1-dev libssh2-php

 

现在你可以测试新安装的PHP的SSH2扩展运行

 

php -m |grep ssh2

 

不要忘记重启

 

service apache2 restart

 

摘自红色黑客联盟(www.7747.net) 原文:http://www.2cto.com/Article/201102/84014.html

linux系统中中php实现ssh自动登录
标签: