安装步骤:
wget https://pypi.python.org/packages/source/p/pssh/pssh-2.3.1.tar.gz
tar -xvf pssh-2.3.1.tar.gz
cd pssh-2.3.1
python setup.py install
使用:
首先,编写一个host列表文件all.list,内容如下:
[email protected]:22 [email protected]:22 |
用法:
1. pssh -A -i -h all.list 'ls ~' # 批量ssh登录到all.list中,然后执行ls命令。-A:输入密码或者key的passphrase;-i:输出远程命令执行结果;-h:host列表文件;'ls ~':为远程host执行的命令。
2. pscp -r -h all.list test/ /cygdrive/d/ # 把本地test及其下面所有文件和目录批量scp到all.list中所有host的/cygdrive/d/下。-r:与scp的-r参数一致,递归copy子目录;-h:host列表文件;test为本地目录;/cygdrive/d/为远程路径。
3. pslurp -r -h ~/all.list /cygdrive/d/get_n_userids.sh . # 把远程的/cygdrive/d/get_n_userids.sh拷贝到本地,将会分别保存在以host为名 的目录下。与pscp相反。
4. prsync -h ~/all.list -a -r /etc/sysconfig /tmp/etc # 将目标服务器的/tmp/network文件复制到本地的/tmp/test目录下,并更名为test。
5. pnuke -h test.txt syslog # 杀死目标服务器的syslog进程,只要ps进程中出现相关词语,就可以杀死。
FAQ:
加上-A参数,但是输入的key密码无效,报错信息:
$ pssh -A -i -h all.list 'uptime'
Warning: do not enter your password if anyone else has superuser privileges or access to your account. Password: [1] 10:48:14 [FAILURE] [email protected]:22Exited with error code 255 Stderr: The authenticity of host '[10.5.23.36]:22([10.5.23.36]:22)' can't be established. ECDSA key fingerprint is SHA256:QYPHGPFFDso7kreFuizuKaKcnEtl/c4uzG6qcIZLA7k. Are you sure you want to continue connecting (yes/no)? Host key verification failed. [2] 10:48:15 [FAILURE] [email protected]:22Exited with error code 255 Stderr: Enter passphrase for key '/home/yhn1792/.ssh/id_rsa': Permission denied (publickey). |
解决:
修改vim /lib/python2.7/site-packages/psshlib/askpass_client.py
将第67行的:
if not prompt.strip().lower().endswith('password:'): |
改为:
if not ( prompt.strip().lower().endswith('password:') or 'enter passphrase for key' in prompt.strip().lower()): |