如何使用Linux脚本自动传递SFTP并传递PEM密钥密码短语?

发布于 2025-02-11 12:46:34 字数 241 浏览 1 评论 0原文

我正在尝试创建一个可以调用的Linux脚本,该脚本可以使用具有关联密码的PEM密钥自动进入外部服务器?

据我所知,它大致类似于:

sftp -i rsa_private.pem -p rsa_private_pass_passpphrase用户名@ip_address@ip_address,

但显然这是在SFTP帐户的假定密码中传递的,而不是PEM键...我是我的...相对不经验Linux脚本,因此任何帮助都将不胜感激!

I'm trying to create a linux script that can be called to automatically sftp into an external server using a pem key which has an associated passphrase?

As far as I can tell it would be roughly something like:

sftp -i rsa_private.pem -p rsa_private_passphrase username@ip_address

But obviously this is passing in an assumed password for the sftp account and not for the pem key... I'm relatively inexperienced with linux scripting so any help at all would be highly appreciated!

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

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

发布评论

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

评论(1

酒儿 2025-02-18 12:46:34

尝试这个棘手的解决方案:
如何通过环境变量传递SSH键密码

基本上,您必须遵循以下步骤:
安装SSH-Agent First

创建一个包含密码

#!/usr/bin/env bash
echo "${0}:${@} : this is for debugging to see if the echo script runs" 1>&2
echo "THEPASSPHRASE"

的Shell Script AskPass.sh,从您的SFTP脚本中启动SSH-Ancent并启动Helper Script

#start the agent
eval $(ssh-agent)

#add your privatekey with ssh-add and the helper script
DISPLAY=":0.0" SSH_ASKPASS="/scripts/askpass.sh" setsid ssh-add /scripts/priv.key </dev/null

#start your sftp session with the privatekey
sftp -v -i /scripts/priv.key  [email protected]

Try this tricky solution :
How to pass an ssh key passphrase via environment variable

basically , you have to follow these steps :
install ssh-agent first

Create a shell script askpass.sh containing the passphrase

#!/usr/bin/env bash
echo "${0}:${@} : this is for debugging to see if the echo script runs" 1>&2
echo "THEPASSPHRASE"

From your sftp script , start ssh-agent and launch the helper script

#start the agent
eval $(ssh-agent)

#add your privatekey with ssh-add and the helper script
DISPLAY=":0.0" SSH_ASKPASS="/scripts/askpass.sh" setsid ssh-add /scripts/priv.key </dev/null

#start your sftp session with the privatekey
sftp -v -i /scripts/priv.key  [email protected]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文