6

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;
}

これらの詳細を使用して接続を作成します。

    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;
    }
}

私が得る結果は、への呼び出しでエラーssh2_auth_pubkey_file()です。

エラーは次のとおりです。

" ssh2_auth_pubkey_file(): 公開鍵を使用した USERNAME の認証に失敗しました: base64 でエンコードされていない無効な鍵データです"

キーにはパスワードがありません。これらのキーを CLI ssh 経由で使用して、サーバーに手動で接続できます。

私は困惑しています。何らかの方法でキーをエンコードする必要がありますか? 提案?

4

2 に答える 2

5

ええと、率直に質問した後、答えを見つけます。開発者のコ​​メントがある別のサイトでこれを見つけました。

gmail dot com の d23d23 は次のように述べ ています。キー生成ツールでファイルを作成した後、ファイルからデータを削除します。」

そのため、openssl を使用して秘密鍵と公開鍵を作成しましたが、上記のようにキー タイプを使用してすべてを 1 行にまとめる必要がありました。ありがとう。

于 2012-06-13T16:08:07.227 に答える