安裝步驟:
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()): |