|  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
Avg. Score:4.5 ± 0.9
Reproduced:19 of 22 (86.4%)
Same Version:9 (47.4%)
Same OS:12 (63.2%)
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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: mistermadness at ya dot ru
New email:
PHP Version: OS:


 [2019-10-11 08:47 UTC] mistermadness at ya dot ru
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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2019-10-11 09:40 UTC]
-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 port 43968 ssh2 [preauth]
Received disconnect from port 43968:11: PECL/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
 [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
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Fri Aug 19 20:03:35 2022 UTC