小编Unk*_*nki的帖子

PHP ssh2_auth_pubkey_file():使用公钥验证失败:密钥数据无效,而不是base64编码

在PHP5.3.3(在CentOS和apache2上)我试图通过PHP脚本连接到SFTP.代码从构造函数中获取密钥和服务器详细信息

function __construct(){
    $this->host     = 'servername.loc';
    $this->port     = SFTP_PORT;
    $this->auth_user    = 'username';
    $this->auth_pub     = '/data/home/username/.ssh/id_rsa.pub';
    $this->auth_priv    = '/data/home/username/.ssh/id_rsa';
    $this->auth_pass    = null;
    $this->connection   = null;
}
Run Code Online (Sandbox Code Playgroud)

并使用这些详细信息来创建连接.

    private function connect(){
    if (!($this->connection = ssh2_connect($this->host, $this->port))) {
        $this->response  = array('code' => "20",
                                 "message" => "Error connecting to SFTP server.");
        return false;
    }
    if (!ssh2_auth_pubkey_file($this->connection, $this->auth_user, $this->auth_pub,
                                $this->auth_priv, $this->auth_pass)) {
        $this->response  = array('code' => "40",
                                 "message" => "Error authenticating to SFTP server with key.");
        $this->disconnect();
        return false;
    }
}
Run Code Online (Sandbox Code Playgroud)

我得到的结果是调用时出错ssh2_auth_pubkey_file().

错误是: …

php ssh

5
推荐指数
2
解决办法
1万
查看次数

标签 统计

php ×1

ssh ×1