php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78661 ssh2_auth_pubkey_file(): Authentication failed using public key: Callback retur
Submitted: 2019-10-11 08:47 UTC Modified: 2019-10-11 09:40 UTC
Votes:30
Avg. Score:4.5 ± 1.0
Reproduced:27 of 30 (90.0%)
Same Version:11 (40.7%)
Same OS:14 (51.9%)
From: mistermadness at ya dot ru Assigned:
Status: Open Package: ssh2 (PECL)
PHP Version: 7.3Git-2019-10-11 (snap) OS: Debian 10
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: mistermadness at ya dot ru
New email:
PHP Version: OS:

 

 [2019-10-11 08:47 UTC] mistermadness at ya dot ru
Description:
------------
PHP 7.3.9-1~deb10u1 (cli) (built: Sep 18 2019 10:33:23) ( NTS )



I have two virtual machines one Debian 9.3 and I connect successfully, another machine is Debian 10.1 and I recieve message ssh2_auth_pubkey_file(): Authentication failed for subscr using public key: Callback returned error.

Difference in libSSH version Debian 9.3 - libssh2/1.7.0, Debian 10 - SSH-2.0-libssh2_1.8.0

It looks like some problem with key auth.

Test script:
---------------
$this->connection = ssh2_connect($host, $port, array('hostkey'=>'ssh-rsa'));
if (ssh2_auth_pubkey_file($this->connection, $username, $rsapath, $rsapubpath)) {
  //echo "Public Key Authentication Successful\n";
} else {
  die('Public Key Authentication Failed');
}

Expected result:
----------------
Connect and recieve Public Key Authentication Successful

Actual result:
--------------
Warning: ssh2_auth_pubkey_file(): Authentication failed for subscr using public key: Callback returned error in /usr/local/nginx/html/cms/admin/classes/sshCron.php on line 18
Public Key Authentication Failed

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-10-11 09:40 UTC] cmb@php.net
-Package: *Encryption and hash functions +Package: ssh2
 [2019-11-21 08:55 UTC] lukas dot zierer at abf dot ch
I have exactly the same issue with PHP 7.3.11-1~deb10u1 on Debian 10. The same script works with identical permissions on my .ssh directory and containing files on Debian 9.6 with PHP 7.1.26.
 [2020-08-07 11:47 UTC] andras dot kovacs at videosqr dot com
I have exactly the same problem. sshd debug as follows:

debug1: /home/myuser/.ssh/authorized_keys:1: matching key found: RSA SHA256:hzJgakOeZOqlCLD8Vo57PimTrqXtrgdCwpodT/vZvRw
debug1: /home/myuser/.ssh/authorized_keys:1: key options: agent-forwarding port-forwarding pty user-rc x11-forwarding
Accepted key RSA SHA256:hzJgakOeZOqlCLD8Vo57PimTrqXtrgdCwpodT/vZvRw found at /home/myuser/.ssh/authorized_keys:1
debug1: restore_uid: 0/0
Postponed publickey for myuser from 10.10.10.3 port 43968 ssh2 [preauth]
Received disconnect from 10.10.10.3 port 43968:11: PECL/ssh2 (http://pecl.php.net/packages/ssh2) [preauth]
 [2020-09-13 20:05 UTC] pierre dot h dot du40 at outlook dot fr
Me too with php 7.3.22 and debian 10.

PHP error is "ssh2_auth_pubkey_file(): Authentication failed for datahosting using public key: Callback returned error" 

My solution is therefore to use a password authentication, but I would like another solution to continue using the key system
 [2021-01-05 13:10 UTC] l dot fuerderer at gmail dot com
I came across this bug report because it seemed as if I had the exact same issue. (Debian 10, PHP 7.3)

But it was just a permission problem of the private key file. Note, that you get the same error message if PHP can't read the private key. Be sure to check your permissions carefully.
 [2021-10-22 09:41 UTC] liyang1025 at gmail dot com
The libssh2 need pem format private key, please check the source code in https://github.com/libssh2/libssh2/blob/3f9d505353d687db14d1486530abf9147bf08033/src/userauth.c#L697
 [2022-04-27 13:48 UTC] pierre dot h dot du40 at outlook dot fr
Reply to liyang1025 at gmail dot com:
No doest work with PEM key
 [2023-05-03 12:49 UTC] amerkulow at yandex dot ru
The issue still exists from 2019 year, so is there any solution?
 [2023-05-07 19:32 UTC] jambu dot atchison at gmail dot com
PHP Version 8.1.2-1ubuntu2.11
SSH-2.0-libssh2_1.10.0

1) I've checked the key file permissions and they are all correctly 0600 and readable by the PHP process. I tested with file_get_contents and am able to output both private and public key file contents from the PHP script.
2) I tested connecting to the remote server using the key file with the ssh command line from the PHP server and it works. `ssh -i KEYFILE USER@HOST`


PHP Warning:  ssh2_auth_pubkey_file(): Authentication failed for USER using public key: Username/PublicKey combination invalid in PHPFILE


ssh2_auth_pubkey_file() returns false
 [2023-05-07 19:38 UTC] jambu dot atchison at gmail dot com
Reply to jambu dot atchison at gmail dot com:

I forgot to mention, this only started occurring after I upgraded the system OS release and PHP version.

It did not happen in the previously installed version:

PHP Version 7.2.24-0ubuntu0.18.04.17
SSH-2.0-libssh2_1.8.0
 [2023-06-14 07:18 UTC] alltravelingnews at gmail dot com
All Travelling News are sharing latest news about Travel, destination, hotel, resturants, beaches, trip, best places etc. More info to visit: (https://alltravellingnews.com)github.com
 [2023-12-07 01:50 UTC] ikechianya1 at gmail dot com
I solved this issue by authorizing my public key in cPanel.

Go to cPanel->SSH Access->Go to your Public key(not .pub key)->Manage

and follow the process to authorize.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Dec 04 18:01:31 2024 UTC