ssh2_auth_pubkey_file fails, ssh credentials succeed on command line - Hack The Tech - Latest News related to Computer and Technology

Hack The Tech - Latest News related to Computer and Technology

Get Daily Latest News related to Computer and Technology and hack the world.

Saturday, July 22, 2023

ssh2_auth_pubkey_file fails, ssh credentials succeed on command line

From the command line this succeeds

ssh roybatty@192.168.xxx.xx -o 'IdentityFile ~/.ssh/transpo_rsa'
Enter passphrase for key '/home/roybatty/.ssh/transpo_rsa':

Using the same user, host, RSA files and passphrase in this PHP

$connection = ssh2_connect('192.168.xxx.xx', 22, array('hostkey'=>'ssh-rsa'));

if (ssh2_auth_pubkey_file($connection, 'roybatty',
                          '/home/roybatty/.ssh/transpo_rsa.pub',
                          '/home/roybatty/.ssh/transpo_rsa', 'Voight_Kampff_test')) {
  echo "Public Key Authentication Successful\n";
} else {
  die('Public Key Authentication Failed');
}

Generates this error:

PHP Warning:  ssh2_auth_pubkey_file(): Authentication failed for roybatty using public key: Callback returned error in /var/www/example.com/test.php on line 12

I am positive the passphrase in the PHP file is the same as the one successfully used on the command line.

Per first note on the man page I (earlier) deleted my first key pair and made new using

ssh-keygen -m PEM -t rsa -f transpo_rsa

authorized_keys was updated with the pub file contents on a newline.

On the remote machine sudo grep 'sshd' /var/log/auth.log gets me

sshd[550981]: Received disconnect from 192.168.yyy.yy port 41254:11: PECL/ssh2 (http://pecl.php.net/packages/ssh2) [preauth] sshd[550981]: Disconnected from authenticating user dmartin 192.168.yyy.yy port 41254 [preauth]

What should my next debugging move be?



source https://stackoverflow.com/questions/76740140/ssh2-auth-pubkey-file-fails-ssh-credentials-succeed-on-command-line

No comments:

Post a Comment