0

This is my first time working with public private keys, and i am getting call back errors. I have been all over trying to find a solutions and im not sure if its something with the setup or what i am using.

My setup is 2 Virtual BOX VM's (Mint Linux hosting the server, Mac OS X hosting the client) Both setup on bridge adapter Both VM running Ubuntu 20.04, both are fresh installations These are the directions used to setup the Public Key (i have gotten pretty fluent in performing this i have done it several times)

https://www.linuxbabe.com/linux-server/setup-passwordless-ssh-login

The setup is done with no paraphrases for testing purposes. I can SSH into the server with no issues My cron jobs run shell connections with no issues

My PHP code is very simple to test out connectivity.

$connection = ssh2_connect('192.168.2.199', 22, array('hostkey'=>'ssh-rsa'));
ssh2_auth_pubkey_file($connection, 'sonyrules', '/opt/www-files/id_rsa.pub', '/opt/www-files/id_rsa');

First error i got is it could not read the file. I fixed this by moving the file out of the home directory and assigning it own directory. That error changes to the current error.

PHP Warning: ssh2_auth_pubkey_file(): Authentication failed for sonyrules using public key: Callback returned error in

This is where i am stuck. I looked in to the /var/log/auth.log and i see the below. I dont think its tell me much on why i am getting a callback error.

Dec 15 14:26:02 test sshd[1359]: Received disconnect from 192.168.2.180 port 59666:11: PECL/ssh2 (http://pecl.php.net/packages/ssh2) [preauth] Dec 15 14:26:02 test sshd[1359]: Disconnected from authenticating user sonyrules 192.168.2.180 port 59666 [preauth]

Any help would be greatly appreciated.

sony1976
  • 1
  • 1

1 Answers1

5

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

J. Nawaz
  • 131
  • 2
  • 6