Report this

What is the reason for this report?

Authentication failed for root using public key when using ssh2_auth_pubkey_file()

Posted on May 20, 2020

I am trying to use ssh using the public key on PHP. I created ssh keys and assigned to droplet successfully. And I can access the root on the terminal without any issue.

As there is a permission issue, I copied the keys to /var/www/html/.

But I am getting an error “ssh2_auth_pubkey_file(): Authentication failed for root using public key:”

Here is my code:

$host = ‘127.0.0.1’; //Droplet ip $port = 22; $user = ‘root’; $pass = ‘pass’; $pubkey = ‘./.ssh/id_rsa.pub’; $prikey = ‘./.ssh/id_rsa’;

$conn = ssh2_connect( $host, $port ); $auth = ssh2_auth_pubkey_file( $conn, $user, $pubkey, $prikey, $pass );

if ( $auth ) { echo ‘Public Key Authentication Successful.’ . PHP_EOL; } else { echo ‘Public Key Authentication Failed.’ . PHP_EOL; }

Please help.

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Start building today

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.