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 経由で使用して、サーバーに手動で接続できます。
私は困惑しています。何らかの方法でキーをエンコードする必要がありますか? 提案?