问题标签 [ssh2]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
659 浏览

c# - 可以让 C# SSH 客户端与 NodeJS SSH 服务器通信吗?

我有一个 C# 应用程序需要通过 SSH 在硬件上运行某些命令。应用程序SSH.Net用于建立连接、发送命令和读取结果。如果我使用 OpenSSH 连接到我的本地机器,我就有这个工作。最后,我想更进一步,设置我自己的 SSH 服务器,这样我就可以一次模拟多个硬件设备(需要模拟有 50 多个设备可以通过 SSH 连接)。

为此,我使用 nodejs 和ssh2包设置了一个简单的 SSH 服务器。到目前为止,我已经连接了客户端,通过了身份验证(现在接受所有连接),并且我可以看到session正在创建一个对象。虽然我碰壁的地方是执行客户端发送的命令。我注意到在对象上ssh2有一个事件,但这似乎永远不会触发(不管我在's中放了什么)。execsessionSSH.NetShellStream

启动连接的 C# 客户端代码如下(command已经定义了要执行的命令字符串):

设置 ssh2 服务器的 nodejs 服务器代码如下:

我见过各种ssh2调用client.exec函数的客户端示例,但我假设我的客户端没有使用ssh2节点包并不重要。有什么我在这里想念的吗?

0 投票
3 回答
19616 浏览

node.js - 无法解析 privateKey:不支持的密钥格式

在我的 Mac book pro with OS Majave 中,我使用 SSH-KEYGEN 为 node.js 模块 SSH2 生成一个新的 SSH 密钥。但是,我收到错误消息:Cannot parse privateKey: Unsupported key format

我用 ssh 命令验证了密钥,它工作正常。但不适用于 node.js 模块 SSH2。

在私钥文件中,头部是 .-----BEGIN OPENSSH PRIVATE KEY-----而结尾是-----END OPENSSH PRIVATE KEY-----.

我检查了模块 ssh2-streams keyParser.js。正则表达式模式RE_HEADER_OPENSSH_PRIV不包括我的标题。任何人都可以帮忙吗?

0 投票
1 回答
821 浏览

php - php(ssh2,隧道),我无法连接我的远程mysql服务器

这是我的代码。mysql 在 ubuntu 设备上。而且我想我可以访问ubuntu,但是mysql连接失败

这个 php 的输出是

如果我使用这条线

然后输出是

显而易见的是 $connection 和 $tunnel 没有问题。我测试过它们。并且运作良好。

请帮我!

0 投票
1 回答
769 浏览

node.js - 节点ssh2客户端中的重复数据输出

我有一个使用 ssh2 npm 模块和 readline 的简单交互式 ssh 客户端。在每一行我将数据发送到服务器流,但由于某种原因输入的命令也发送

但是每个输入的命令都是重复的。如何做到没有重复?谢谢!

输出:

预期输出:

0 投票
1 回答
232 浏览

php - 使用 PHP SSH2 将文本添加到文件中

我正在尝试使用 PHP SSH2 创建并附加到文本文件。我发送的命令是这样的:

该文件已创建,但文本未附加到它。

感谢任何关于我哪里出错的意见。

0 投票
1 回答
5918 浏览

javascript - 转换可读流以将其保存为本地文件

我正在使用 ssh2-sftp-client 从远程服务器获取文件。我在可读流中获取文件。我想将此可读流转换为所需的文件(sample.png 作为 png 文件,sample.doc 文件作为 doc 文件等)

这是我的代码-

我想将此文件保存在本地。文件是一个可读流,如下所示 -

0 投票
1 回答
257 浏览

javascript - 将图像保存到用户发送的 sftp 远程服务器

我想使用 ssh2-sftp-client 将文件上传到 sftp 远程服务器。我在发布请求中从用户那里获取文件以及目的地。我正在使用 multer 来处理文件。

我收到错误:

0 投票
1 回答
996 浏览

php - 通过 private.key 连接到 SFTP 服务器的问题

我在通过私钥连接到 SFTP 服务器时遇到问题。首先,我有 id_rsa.pkk 文件。我使用 PuttyGen 程序加载密钥并将其转换为 open-ssh 私钥作为 privateKey.pem,开始为:

和 publicKey.pub 作为

当我通过控制台发送它时:

一切都好。控制台要求我输入密码。当我输入密码时,它将我正确连接到服务器......

但是当我尝试使用

使用 $pubKey 作为 publicKey.pub 和 $privKey 作为 privateKey.pem 我有一个错误

当我尝试使用 phpseclib 作为

我登录失败。

我还尝试通过控制台转换 ppk 文件:

但同样的问题......我做错了什么?

编辑:返回 $sftp->getLog();

编辑:解决方案:使用 phpseclib 2.0.3 版后问题得到解决:)

0 投票
1 回答
90 浏览

meteor - Meteor MUP 使用 ssh ed25519 验证失败

问题

我想使用mup setup. 但是它在所有可能的配置中都失败了:

失败,其中模块ssh2(似乎是处理客户端身份验证请求的 MUP 的一部分)无法解析密钥的(未知)格式。

ssh -i失败,因为我的服务器只接受使用密钥身份验证( )的登录

ssh2由于未知的密钥格式,也失败了。请注意,从默认 OSX 终端使用我的 ssh-agent 可以按预期工作。

背景

节点ssh2模块似乎不支持 ssh ed25519,我只能使用 ssh 密钥登录服务器。

问题

是否有任何可能的方法在mup setup不使用节点模块 ssh2 的情况下进行身份验证,或者我是否无法使用 MUP?

0 投票
1 回答
850 浏览

node.js - SFTP in node downloads blank files only

I've been trying for a while now to download a file from my SFTP file storage to my local machine - And visited a number of stack posts - Like this one:

SFTP modules in Node to download and delete files

However, I cannot get it to work. I have this code - Which is exactly the same as that posted by Mscdex in the question I have linked to - But it does not work.

It does download a file to my local machine - However, this is a totally blank file. At first I thought it was due to the file format I need to download - .csv.gz - But even when testing with simple .json and .html files, it still downloads a blank file.

Can anyone shed some light onto why I'm running into this issue? My end goal is to download the file as a stream and push it to the client side browser via the response headers.

UPDATE

I have found a way to download the file, instead of using the npm module ssh2-sftp-client, I used npm module ssh2. I can download the file fine with this code:

However, Can anybody tell me how I would return a stream using this code rather than downloading the file as I want to be able to push the stream to the client and download the file in the browser.

Many thanks in advance,

G