PHP ssh2_auth_pubkey_file (): Public key authentication error: invalid key data, not base64 encoded

In PHP5.3.3 (on CentOS and apache2) I am trying to connect to SFTP via php script. The code captures server keys and data from the constructor

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

and uses this data to create the connection.

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

As a result, I get an error message when called ssh2_auth_pubkey_file().

Error:

" * ssh2_auth_pubkey_file (): Authentication error for USERNAME using public key: invalid key data, not base64 encoded * "

There is no password key, and I can use these keys through the ssh CLI to manually connect to the server. I'm at a dead end. Do I need to encode keys somehow? Suggestions?

. - Unkul Munki

+5
2

, , pubkey, , ( , ).

, . ssh2, ssh2 , wuth libgcrypt openssl. - PEM PEM openssl:

~/.ssh> openssl rsa -in id_rsa -out id_rsa.pem

ssh2_auth_pubkey_file() PHP script id_rsa.pem id_rsa . .

+5

, , , . .

d23d23 gmail dot com : " , , 1 ( ), . libssh2, ."

, openssl , , , . .

+4

All Articles