PHP ssh2_auth_pubkey_file(): Authentication failed using public key: Invalid key data, not base64 encoded

前端 未结 2 1205
予麋鹿
予麋鹿 2020-12-19 12:06

In PHP5.3.3 (on CentOS and apache2) I am attempting to connect to a SFTP via a php script. The code grabs the keys and server details from the constructor

fu         


        
2条回答
  •  萌比男神i
    2020-12-19 12:19

    The prerequisite that you mention, namely the pubkey file not to have any comments and not even have a trailing newline is incorrect (and the newline thingy absurd when you think it through).

    If your scriptfails, you have prob. sooner stumbled into the ssh2 bug that makes ssh2 fail when it is compiled wuth libgcrypt instead of openssl. The workaround is to create a PEM formatted copy of your private key file in PEM format with openssl:

    ~/.ssh> openssl rsa -in id_rsa -out id_rsa.pem
    

    Then, in ssh2_auth_pubkey_file() in your PHP script, use id_rsa.pem as privkey file instead of id_rsa, and omit the passphrase. That should make it work.

提交回复
热议问题