简体   繁体   English

phpseclib使用sftp - ssh连接到localhost

[英]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. 我正在使用phpseclib( https://github.com/phpseclib/phpseclib ),我遇到了一个我不知道如何解决的问题。

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. 所以基本上我想使用PHP通过SSH连接到运行脚本的同一台服务器来执行一些SFTP事务。

I tried ssh localhost on command line and it logs me in using my SSH key-pair. 我在命令行上尝试了ssh localhost ,它使用我的SSH密钥对登录。

I implemented phpseclib to download/upload files from/to a remote server. 我实现了phpseclib从/向远程服务器下载/上传文件。 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. 但是,我无法模拟SFTP类,因为需要为每个连接启动对象,有没有办法测试我编写的函数,基本上只是一个文件下载和处理数据函数。

My guess: your ~/.ssh/id_rsa file is the private key corresponding to the public key in ~/.ssh/authorized_keys . 我猜:你的~/.ssh/id_rsa文件是与~/.ssh/authorized_keys公钥对应的~/.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. 因此,当您尝试使用ssh localhost登录时,它实际上并没有在没有身份验证的情况下登录您 - 它使用公钥登录但您却没有意识到。

A few other less likely possibilities: 其他一些不太可能的可能性:

  1. You have ssh-agent installed and are using that without realizing it. 您已安装ssh-agent并且正在使用它而未实现它。
  2. You're authentication with host-based authentication (which phpseclib doesn't support) 您使用基于主机的身份验证进行身份验证(phpseclib不支持)

Doing ssh -v localhost and then posting what it says might be helpful. 执行ssh -v localhost ,然后发布它说的内容可能会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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