Question
Authentication failed for root using public key when using ssh2_auth_pubkey_file()
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 “ssh2authpubkey_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/idrsa.pub’;
$prikey = ’./.ssh/idrsa’;
$conn = ssh2connect( $host, $port );
$auth = ssh2authpubkeyfile( $conn, $user, $pubkey, $prikey, $pass );
if ( $auth )
{
echo 'Public Key Authentication Successful.’ . PHPEOL;
}
else
{
echo 'Public Key Authentication Failed.’ . PHPEOL;
}
Please help.
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
×
Sorry code was not formatted. Here is the formatted code