linux - 没有 key 的 ssh 并使用 bash 脚本收集输出

标签 linux bash ssh expect

我想创建一个 bash 脚本,它将使用 ssh 登录到我网络中的所有 linux 服务器,并将“uptime”命令的输出收集到本地文件。这些本地服务器和远程服务器之间没有安装 key 对。所以我需要在脚本本身中提供密码(所有远程服务器的用户名和密码都相同)。我知道这不是一种安全的方法,但这只是为了学习目的。我看到“expect”命令可用于带密码的 ssh 登录,但混淆了如何将它与提供服务器状态的“uptime”命令一起使用。所以我的要求是

1. I have local server test1 which contains a text file 'server_status.txt' 
2. I need a script in test1 that will try to login to all the remote servers (say 192.168.0.1 to 192.168.0.50) using the same username and password. It will execute the command 'uptime' once logged in to the remote servers and store the output to the local file 'server_status.txt'

最佳答案

REVOKE:将您的公钥粘贴到服务器的 /path2userthatshouldlogon/.ssh/authorized_keys 中并使用 ssh user@host commandtoexecute 远程运行您的命令

由于想在没有 key 的情况下建立连接。 更新:看看sshpass如果您确实需要密码,不推荐

关于linux - 没有 key 的 ssh 并使用 bash 脚本收集输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27941154/

相关文章:

linux - 无法在 AWS 中进行 SSH

linux - 对两个文件中一行的每个元素求和

linux - 在不同浏览器中测试网站的环境设置

linux - 如何同时打开三个终端(进程)

linux - 在 bash 中比较 *nix 时间戳的最佳方法

bash - 更多coproc问题

git 权限被拒绝(公钥、gssapi-keyex、gssapi-with-mic)

使用 phpseclib 通过 SSH 连接到 MySQL 的 PHP 代码

windows - NodeJS 可以自己重启吗?

linux - 在csh中设置环境变量