Re: Hoping for a working example of SFTP in PHP
[email protected] ("Stefan A.")
| Newsgroups | php.general |
|---|---|
| Message-ID | <CA+d_MekYSjuwzo4ZMgLw4Fe_BWJ+VmCL7uREf2T0ATMB-7fohg@mail.gmail.com> |
Also according to man page for ssh2_auth_pubkey_file ( https://www.php.net/manual/en/function.ssh2-auth-pubkey-file) the public key should be in OpenSSH format. This means that you should use the public key that starts with ssh-rsa (that's the OpenSSH format). From what I understand from you've tried both, so I don't really know what else to say and I am also working on Ubuntu, so I am unable to try to replicate your issue. Sorry and good luck! On Tue, Feb 2, 2021 at 1:46 PM Stefan A. <[email protected]> wrote: > I was mainly interested in the last two file_get_contents() calls. If > there was some sort of a permission issue the script should have output one > or two error messages. But since that's not the case, then probably your > script can read the keys just fine, and the issue is elsewhere. I can also > tell that the process that executes the php script runs under the user > SYSTEM (which is not that helpful). > > Some more info I found (which you've probably read already) > > "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." > > from here > https://stackoverflow.com/questions/11007090/php-ssh2-auth-pubkey-file-authentication-failed-using-public-key-invalid-key/20730073 > > Maybe give that a go as well. > > > > On Tue, Feb 2, 2021 at 1:36 PM David Spector < > [email protected]> wrote: > >> Stefan, I ran your program with w.pub and w.key, two of the local keys I >> have been testing with. My main question right now is what format >> ssh2_auth_pubkey_file expects the public and private keys to have. There >> are many formats for key files. >> >> My w.pub starts with >> >> -----BEGIN RSA PUBLIC KEY----- >> >> and my w1.pub starts with >> >> ssh-rsa >> >> Anyway, here is the output of your program: >> >> ==== >> SYSTEM >> 0 >> >> Array >> ( >> [0] => 1492101109 >> [1] => 28991922601259292 >> [2] => 33206 >> [3] => 1 >> [4] => 0 >> [5] => 0 >> [6] => 0 >> [7] => 426 >> [8] => 1612210905 >> [9] => 1612210511 >> [10] => 1612209151 >> [11] => -1 >> [12] => -1 >> [dev] => 1492101109 >> [ino] => 28991922601259292 >> [mode] => 33206 >> [nlink] => 1 >> [uid] => 0 >> [gid] => 0 >> [rdev] => 0 >> [size] => 426 >> [atime] => 1612210905 >> [mtime] => 1612210511 >> [ctime] => 1612209151 >> [blksize] => -1 >> [blocks] => -1 >> ) >> >> Array >> ( >> [0] => 1492101109 >> [1] => 29836347531409753 >> [2] => 33206 >> [3] => 1 >> [4] => 0 >> [5] => 0 >> [6] => 0 >> [7] => 1766 >> [8] => 1612213452 >> [9] => 1612209076 >> [10] => 1612209151 >> [11] => -1 >> [12] => -1 >> [dev] => 1492101109 >> [ino] => 29836347531409753 >> [mode] => 33206 >> [nlink] => 1 >> [uid] => 0 >> [gid] => 0 >> [rdev] => 0 >> [size] => 1766 >> [atime] => 1612213452 >> [mtime] => 1612209076 >> [ctime] => 1612209151 >> [blksize] => -1 >> [blocks] => -1 >> ) >> ==== >> >> Please tell me what this output means to you. >> >> David >> >