使用 Node.JS 运行的脚本通过 SSH 导出 PGP 密钥

发布于 2025-01-12 07:48:57 字数 770 浏览 3 评论 0原文

我正在尝试使用此脚本将 PGP 子密钥导出到远程计算机:

#!/bin/bash
ssh-keyscan -H $REMOTE_MACHINE >> /root/.ssh/known_hosts
gpg2 --verbose --export-secret-key \
    $EXPORT_THIS_ID | sshpass -p $REMOTE_PASS \
    ssh $REMOTE_USER@$REMOTE_MACHINE \
    gpg2 --verbose --import
echo '' > /root/.ssh/known_hosts

并得到以下响应:

# host.mynet.lan:22 SSH-2.0-OpenSSH_8.0
# host.mynet.lan:22 SSH-2.0-OpenSSH_8.0
# host.mynet.lan:22 SSH-2.0-OpenSSH_8.0
# host.mynet.lan:22 SSH-2.0-OpenSSH_8.0
# host.mynet.lan:22 SSH-2.0-OpenSSH_8.0
gpg: writing to stdout
gpg: WARNING: nothing exported
Permission denied, please try again.

这是从 Nodejs 后端完成的,该脚本使用 child.spawn 运行,并且响应通过管道传输到前端以显示给用户。

我看到 gpg 说写入标准输出,但我不知道从这里去哪里。

I'm trying to export PGP sub keys to a remote machine using this script:

#!/bin/bash
ssh-keyscan -H $REMOTE_MACHINE >> /root/.ssh/known_hosts
gpg2 --verbose --export-secret-key \
    $EXPORT_THIS_ID | sshpass -p $REMOTE_PASS \
    ssh $REMOTE_USER@$REMOTE_MACHINE \
    gpg2 --verbose --import
echo '' > /root/.ssh/known_hosts

and am getting a response of:

# host.mynet.lan:22 SSH-2.0-OpenSSH_8.0
# host.mynet.lan:22 SSH-2.0-OpenSSH_8.0
# host.mynet.lan:22 SSH-2.0-OpenSSH_8.0
# host.mynet.lan:22 SSH-2.0-OpenSSH_8.0
# host.mynet.lan:22 SSH-2.0-OpenSSH_8.0
gpg: writing to stdout
gpg: WARNING: nothing exported
Permission denied, please try again.

This is done from a nodejs backend, the script is run using child.spawn and the response is piped to the frontend to be displayed to the user.

I see gpg says writing to stdout, but am not sure where to go from here.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甜味超标? 2025-01-19 07:48:57

上面的脚本完美运行。我的问题是如何将 $REMOTE_PASS 变量传递给脚本。对于遇到这种情况的人,请注意密码中的特殊字符。如有必要,将传递封装在 ""(引号)中。出于安全考虑,如果密码高度机密,请不要处理这样的密码。

就我而言,初始连接后密码不再可用。

The above script works perfectly. My issue was how I was passing the $REMOTE_PASS variable to the script. For those who come across this, beware of special chars in the password. Encapsulate the pass in ""(inverted commas) if necessary. For security purposes don't handle passwords like this if the password is highly secret.

In my case, the password is no longer usable after this initial connection.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文