- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
据我所知,命令 ssh
或 scp
没有/采用密码参数。否则,我可以将密码保存在 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 密码的开发人员能够使用它(所以我猜公钥身份验证将不起作用,因为它将密码存储在系统中).
开放赏金
从目前的所有答案以及我对这些解决方案的分析来看,看起来除了公钥身份验证之外,其他所有方式都是不安全的。我还不确定使用 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/
我想知道使用 SCP 传输文件时使用的默认模式是什么(ASCII 或二进制,如 FTP)。 SCP 中是否有任何文件模式概念?它是如何工作的 ? 最佳答案 FTP中的文件传输方式用于解决不同操作系统行
我想知道是否有一种方法可以让我通过remote1主机直接从本地计算机对remote2主机的文件进行SCP。 网络仅允许从远程 1 主机连接到远程 2 主机。另外,remote1 主机和remote2
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 已关闭 6 年前。 此问题是由拼写错误或无法再重现的问题引起的。虽然类似的问题可能是 on-topic在这里
我正在寻找一个多平台解决方案,可以让我检查 scp命令可用。 问题是 scp 没有 --version命令行,当不带参数调用时,它将返回退出代码 1 (错误)。 更新:如果不清楚,多平台我的意思是一个
关闭。这个问题是off-topic .它目前不接受答案。 想改进这个问题? Update the question所以它是on-topic对于堆栈溢出。 10年前关闭。 Improve this qu
我在 Windows A 上运行 freeSSHD,需要通过 scp 传输文件。运行 freesshd 的 Windows 可以通过 ssh 客户端连接。但是 Windows 上的 WinSCP 和
我正在我的 Windows 机器上使用腻子通过 ssh 访问 ubuntu 服务器,并尝试将单个文件下载到我的本地 Windows 机器 我的 Windows 用户名是 Mark,每个 cmd 的主机
所以我发现我可以通过标准输入对 scp 执行以下操作: 目录创建 scp -tr . stdin -> D0755 0 stdin -> \x00 文件写入 scp -tr . stdin -> C
请为我在工作中面临的问题提供您的专家选项。 Ant SCP 任务不起作用 - 因为我可以使用 cygwin 进行 scp。 本地环境:windows 7 64 位、Jdk 1.6.0.24、Ant-1
我需要重新安装我们的一台服务器,作为预防措施,我想移动 /home、/etc、/opt和 /Services 到备份服务器。 但是,我有一个问题:由于存在大量符号链接(symbolic link),因
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a software
我有一个小型应用程序,它试图执行十几个并行“scp”运行,从远程系统中提取文件。通常,它运行良好。有时,一两个 scp 悄悄地死掉了。(如果从 Linux 中拉出,则为“安静”。如果从 HP-UX 中
我有一个脚本可以将文件从一台服务器传输到另一台服务器,但它给出了一个错误: Net::SCP::Error (SCP did not finish successfully ()): 有谁能够帮助我?
下面是我的 shell 脚本片段,我在其中执行 scp 命令将文件从 machineB 复制到 machineA。 for element in ${x[$key]}; do # no quote
我有一个适用于不同客户端的脚本,需要将 SCP 文件发送到不同的主机。根据客户端和服务器的组合,我可能需要使用密码身份验证或公钥身份验证。我真的无法提前知道使用哪一个。 我使用的 SCP 有 2 个
我正在尝试使用 libssh2 scp 从实例中检索文件。 为了确保我的用户名、密码和 key 正确无误,我做了: sudo scp -v -P #port -i /home/username/.ss
我正在尝试使用 scp 在两台 Mac (OS 10.6.8) 之间传输文件。但它失败了,因为我的目录/文件名中有空格。我无法更改目录/文件名。 在我的 Mac 的终端中工作时,我经常使用\符号来表示
我需要一些帮助来在 xml 中构建这一行。对于谷歌内容 API 我想要得到的结果是 25 目前我的代码输出这一行 25这是不正确的。 这是我的代码 b = Nokogiri::XML::Builder
我正在使用命令: docker-machine scp 管理器:/home/docker/foo.txt 。 但是,Windows PowerShell 返回“您必须在本地拥有 scp 二进制文件的副
我们知道 String将被存储在SCP(字符串常量池)区域: 1.以同样的方式String[]也存储在SCP中?我的意思是每个数组包含一个 String ,那么这又会被存储在 SCP 中吗? 2.那么
我是一名优秀的程序员,十分优秀!