tar + ssh传输文件

(引用)[https://serverfault.com/questions/326490/running-multiple-scp-threads-simultaneously]

I would do it like this:
tar -cf - /manyfiles | ssh dest.server 'tar -xf - -C /manyfiles'

Depending on the files you are transferring it can make sense to enable compression in the tarcommands:
tar -czf - /manyfiles | ssh dest.server 'tar -xzf - -C /manyfiles'

It may also make sense that you choose a CPU friendlier cipher for the ssh command (like arcfour):tar -cf - /manyfiles | ssh -c arcfour dest.server 'tar -xf - -C /manyfiles'

Or combine both of them, but it really depends on what your bottleneck is.
Obviously rsync will be a lot faster if you are doing incremental syncs.

expect 捕捉ssh自动输入

sudo yum install -y expect
  • 批量ssh公钥往目标机上传
#!/usr/bin/expect -f

set login "install"
set addr [lindex $argv 0]
set pw [lindex $argv 1]
spawn ssh-copyid $login@$addr
expect "*yes/no*" {
send "yes\r"
expect "*?assword*" { send "$pw\r" }
} "*?asswor*" { send "$pw\r" }
interact
#!/bin/bash

password=`cat /root/installpassword.txt`

for j in 10 11 12 13 14 15 16 17 18 19 20
do

./expectscript 192.168.1.$j $password

done