gpt4 book ai didi

bash - 如何从 bash 脚本中使用 ssh?

转载 作者:行者123 更新时间:2023-11-29 08:40:12 24 4
gpt4 key购买 nike

我正在尝试创建一个 ssh 连接并从脚本中在远程服务器上做一些事情。

但是终端提示我输入密码,然后在终端窗口而不是脚本中打开连接。在我退出连接之前,这些命令不会执行。

如何从 bash 脚本中使用 ssh?

最佳答案

  1. 如果您希望密码提示消失,请使用基于 key 的身份验证 (described here)。

  2. 要通过 ssh 远程运行命令,您必须将它们作为参数提供给 ssh,如下所示:

root@host:~ # ssh root@www 'ps -ef | grep apache | grep -v grep | wc -l'

关于bash - 如何从 bash 脚本中使用 ssh?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1895185/

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