简体   繁体   中英

phpseclib connect to localhost using sftp - ssh

I'm working with phpseclib ( https://github.com/phpseclib/phpseclib ) and I come across a problem that I don't know how to solve.

So basically I would like to use PHP to connect to the same server that the script is running on via SSH to perform some SFTP transaction.

I tried ssh localhost on command line and it logs me in using my SSH key-pair.

I implemented phpseclib to download/upload files from/to a remote server. Now I am writing unit tests for the code I've written. However, I cannot mock SFTP class since the object needs to be initiated for every connection, is there a way to test the function that I've written, basically just a file download and process data function.

My guess: your ~/.ssh/id_rsa file is the private key corresponding to the public key in ~/.ssh/authorized_keys . So when you try to login with ssh localhost it isn't actually logging you without authentication - it's logging you in with a public key but you just don't realize it.

A few other less likely possibilities:

  1. You have ssh-agent installed and are using that without realizing it.
  2. You're authentication with host-based authentication (which phpseclib doesn't support)

Doing ssh -v localhost and then posting what it says might be helpful.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM