phpseclib connect to localhost using sftp - ssh

做~自己de王妃 提交于 2019-12-11 04:24:55

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/41584098/phpseclib-connect-to-localhost-using-sftp-ssh

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!