ssh2_auth_pubkey_file authentication always fails ssh2_auth_pubkey_file authentication always fails php php

ssh2_auth_pubkey_file authentication always fails


The error in this case was that the keys were generated by the root user, but they need to be accessible by the web server group/owner www-data.

I didn't like the idea of keeping ssh keys in a web folder open to www-data, so I moved the key files to a new user's home directory (/home/keyuser/) then made them accessible to www-data. Authentication was successful.

Even though the original error was saying it found the file, it couldn't read the file.

A better debug method is to try reading the file via php:

$prv_key = file_get_contents('/var/www/application/files/id_dsa');print "<pre>";var_export($prv_key);print "</pre>";