Understanding Errors in Public Key Authentication

Asked 1 years ago, Updated 1 years ago, 401 views

I'd like to authenticate the public key using the ssh2_auth_pubkey_file function in PHP.
I am having a hard time because I cannot authenticate with the following message.
If you have any advice such as whether this is the cause, please take care of it.

$connection=ssh2_connect($host,$port);
if(!$connection){
   // connection failure
}

$user='user';
$pubKey='/home/user/.ssh/authorized_keys';
$priKey='../id_rsa';

if(!ssh2_auth_pubkey_file($connection,$user,$pubKey,$priKey)){←★Error here
   // authentication failure
}

Warning Error: ssh2_auth_pubkey_file():Authentication failed for user using public key:Unable to open public key file

The public keys are placed below, each permission is 755, .ssh is 700 and authorized_keys is 600.
/home/user/.ssh/authorized_keys

*Public key authentication is available from TeraTeam.

php ssh scp

2022-12-24 06:27

1 Answers

If PHP operates with web server privileges such as Apache, files under the user's home directory may not be read due to access privileges.

The behavior of the web server depends on the environment, but it can be www-data, httpd, apache, nginx, etc.

The public key must be placed in a location accessible to the above users, or the original file must be authorized to be accessible to the above users/groups.

reference:
ssh2_auth_pubkey_file authentication always fails-Stack Overflow


2022-12-24 06:54

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.