ssh2_auth_pubkey_file getting error Callback returned error (PHP 7.4, Ubuntu 20)

one text

Solution:

I also faced similar issue recently. It could be because of the private key file. A PEM format key is required but you might have OpenSSH format key. Please check if your private key starts with this: -----BEGIN OPENSSH PRIVATE KEY-----

If this is the case you have change the format. Just run this:

ssh-keygen -p -m PEM -f /path/to/key

For me this worked.

You can look into the first comment of this documentation: https://www.php.net/manual/en/function.ssh2-auth-pubkey-file.php

Also these posts: Openssh Private Key to RSA Private Key https://serverfault.com/questions/939909/ssh-keygen-does-not-create-rsa-private-key

Source