phpseclib 使用 sftp - ssh 连接到本地主机 [英] phpseclib connect to localhost using sftp - ssh

查看:65
本文介绍了phpseclib 使用 sftp - ssh 连接到本地主机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 phpseclib(https://github.com/phpseclib/phpseclib)我遇到了一个我不知道如何解决的问题.

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

所以基本上我想使用 PHP 通过 SSH 连接到运行脚本的同一台服务器来执行一些 SFTP 事务.

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.

我在命令行上尝试了 ssh localhost 并且它使用我的 SSH 密钥对让我登录.

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

我实现了 phpseclib 来从/向远程服务器下载/上传文件.现在我正在为我编写的代码编写单元测试.但是,我无法模拟 SFTP 类,因为每个连接都需要启动对象,有没有办法测试我编写的函数,基本上只是文件下载和处理数据函数.

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.

推荐答案

我的猜测:你的~/.ssh/id_rsa文件就是~/中公钥对应的私钥.ssh/authorized_keys.因此,当您尝试使用 ssh localhost 登录时,它实际上并没有在未经身份验证的情况下登录您 - 它是使用公钥登录您,但您只是没有意识到.

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. 您已经安装了 ssh-agent 并且在不知不觉中使用了它.
  2. 您正在使用基于主机的身份验证(phpseclib 不支持)进行身份验证

执行 ssh -v localhost 然后发布它所说的内容可能会有所帮助.

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

这篇关于phpseclib 使用 sftp - ssh 连接到本地主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆