gpt4 book ai didi

bash - 使用变量的值作为 scp、ssh 等的密码,而不是每次都提示用户输入

转载 作者:行者123 更新时间:2023-11-29 08:49:51 25 4
gpt4 key购买 nike

据我所知,命令 sshscp 没有/采用密码参数。否则,我可以将密码保存在 shell 变量中,并可能摆脱输入密码提示。如果我在 shell 脚本中编写 scp 命令,它会提示用户输入密码。我的脚本中有多个 ssh 和 scp 命令,我不希望用户每次都输入密码。我宁愿一开始就将密码保存在 shell 变量中(通过询问一次密码),然后将它用于每个 ssh 或 scp。

我在 this question 中读到“公钥识别” .是否与我正在寻找的解决方案有关?

更新
我读了 How to use ssh command in shell script?为什么在命令行上指定密码是不安全的。使用 expect 是否也存储密码并且是世界可见的(使用 ps aux)?这是使用 expect 的安全问题吗?

进一步说明
为了进一步说明,我正在编写此 shell 脚本来自动执行代码和数据库备份、上传代码、运行必要的数据库查询,以及执行 LAMP project 的新版本发布所需的所有操作。从开发者系统到远程实时服务器。我的 shell 脚本将存在于每个开发人员实例中项目的主要代码库中。

要求

  • 我希望所有知道 SSH/FTP 密码的开发人员(都可能在不同的远程系统上工作)能够通过仅在运行时输入一次相同的 ssh/ftp 密码来使用 shell。我希望密码是 ssh/ftp 密码

    注意 - 我不希望其他不知道 SSH 密码的开发人员能够使用它(所以我猜公钥身份验证将不起作用,因为它将密码存储在系统中).

  • 我不想要任何命令行解决方案将密码存储在系统的某些日志中,并且可以使用 ps aux 或其他东西在全世界可见。

开放赏金
从目前的所有答案以及我对这些解决方案的分析来看,看起来除了公钥身份验证之外,其他所有方式都是不安全的。我还不确定使用 expect 是否不安全。我认为这对我来说是正确的解决方案。在那种情况下,我在尝试执行此操作时收到命令未发现错误,正如已经对其中一个答案发表评论的那样。

来自 http://www.debianadmin.com/sshpass-non-interactive-ssh-password-authentication.html -

First and foremost, users of sshpass should realize that ssh’s insistance on only getting the password interactively is not without reason. It is close to be impossible to securely store the password, and users of sshpass should consider whether ssh’s public key authentication provides the same end-user experience, while involving less hassle and being more secure.

那么,是否无法通过输入 ssh/ftp 密码安全地运行多个 ssh、scp 命令(如果只在运行时运行一次?请再次阅读我的要求部分。

还有,谁能解释一下-

In particular, people writing programs that satisfies are meant to communicate the above points)password programatically are encouraged to use an anonymous pipe and pass the pipe’s reading end to sshpass using the -d option.

这是否意味着一切皆有可能?

最佳答案

确实,您肯定会想研究设置 ssh key ,而不是在 bash 脚本中保存密码。如果 key 是无密码的,则 ssh/scp 不需要用户输入。您只需将其设置为在两端使用 key ,瞧,安全通信。

但是,如果我不这么说,我会被否决的。许多人认为无密码 ssh key 是一个 Bad Idea(TM)。如果有人拿到了 key ,他们就有了完全的访问权限。这意味着您依赖其他安全措施(例如文件权限)来确保您的密码安全。

另外,查看 ssh-agent。它允许您对其进行设置,以便您拥有受密码保护的 ssh key ,但您只需输入一次,它将为您管理 key 的密码,并在必要时使用它。在我家里的 linux 机器上,我将 ssh-agent 设置为在我的 .xinitrc 文件中运行,这样它会提示我一次,然后启动 X.YMMV。

更新:
关于您的要求,密码保护公钥身份验证 + ssh-agent 似乎仍然合适。只有知道 SSH/FTP 密码的开发人员才能启动 ssh-agent,输入密码,ssh-agent 会在 session 的其余部分管理公钥的密码,不再需要交互。

当然,它如何存储它完全是另一回事。 IANASE,但有关使用 ssh-agent 的安全问题的更多信息,我发现 symantec 的文章非常有用:http://www.symantec.com/connect/articles/ssh-and-ssh-agent

"The ssh-agent creates a unix domain socket, and then listens for connections from /usr/bin/ssh on this socket. It relies on simple unix permissions to prevent access to this socket, which means that any keys you put into your agent are available to anyone who can connect to this socket. [ie. root]" ...

"however, [..] they are only usable while the agent is running -- root could use your agent to authenticate to your accounts on other systems, but it doesn't provide direct access to the keys themselves. This means that the keys can't be taken off the machine and used from other locations indefinitely."

希望您不会处于尝试使用不受信任的 root 系统的情况。

关于bash - 使用变量的值作为 scp、ssh 等的密码,而不是每次都提示用户输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4594698/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com