1、scp远程拷贝命令
推:scp -P22 -r -p /tmp/ root@192.168.1.102:/tmp
拉 :scp -P22 -r -p root@192.168.1.102:/tmp/liu /opt/
参数说明:
-P (大写)(ssh小写)接端口,默认不用
-r 递归表示拷贝目录
-p 表示在拷贝前后保持文件或目录属性
-l 限制速度
2、expect 交互 分发公钥脚本避免了人员输入yes和密码
[root@NFS_Server scripts]# cat fenfa_expect.exp 第一部分脚本文件
#!/usr/bin/expect
if { $argc != 2} {
send_user "usage: expect fenfa_sshkey.exp file host\n"
exit
}
#define var
set file [lindex $argv 0]
set host [lindex $argv 1]
set password "666666"
spawn ssh-copy-id -i $file "-p 22 root@$host"
expect {
"yes/no" {send "yes\r";exp_continue}
"*password" {send "$password\r"}
}
expect eof
exit -onexit {
send_user "ok"
}
[root@NFS_Server scripts]# cat fenfa_host.sh 第二部分文件
#!/bin/sh
. /etc/init.d/functions
for ip in 102 104
do
expect fenfa_expect.exp ~/.ssh/id_dsa.pub 192.168.0.$ip
if [ $? -eq 0 ];then
action "$ip" /bin/true
else
action "$ip" /bin/false
fi
done