В PHP5.3.3 (в CentOS и apache2) я пытаюсь подключиться к SFTP через php-скрипт. Код получает ключи и сведения о сервере из конструктора
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 для подключения к серверу вручную.
Я в тупике. Нужно ли как-то кодировать ключи? Предложения?