使用ssh在多个主机上执行异常远程命令
ssh-commander的Python项目详细描述
ssh指挥官
此命令行工具允许您在多个远程主机上执行各种命令, 使用ssh协议。因此,您将得到每台主机生成的 指定的命令。
您只需指定一个纯文本文件,其中包含要连接到的远程主机列表(域名 或IP地址),以及要在这些地址上执行的命令的逗号分隔列表。请注意 所有目标主机的访问凭据(用户和密码)必须相同!.
要求
确保您的系统满足以下要求:
安装
安装此工具的推荐方法是使用pip
:
pip install ssh-commander
用法
使用ssh-commander
时,请遵循以下语法:
Execute remote commands on several hosts, with SSH.
usage: ssh-commander [-h] [-p PORT] [-v] FILE USER COMMANDS
Excecute remote commands on several hosts, with SSH.
positional arguments:
FILE Plain text file with list of hosts
USER User to login on remote hosts
COMMANDS Comma separated commands to be executed on remote
hosts
optional arguments:
-h, --help show this help message and exit
-p PORT, --port PORT Specify SSH port to connect to hosts
-v, --version Show current version
首先,记住创建一个文本文件(可以随意命名),其中 列出目标主机。其内容可能如下:
# This is a comment. It'll be ignored!.
192.168.0.10
192.168.0.11
192.168.0.12
另外,请注意,用户提供的密码只会被询问 一次。因此,这些凭据在所有目标主机上都应该有效!.
示例
假设您有一些托管交换机(或路由器):
ssh-commander hosts.txt root "terminal length 0, sh port-security"
它们可能是一些gnu/linux服务器,以及:
ssh-commander hosts.txt foones "hostname, whoami"