shell脚本 添加其他机器免密

#!/bin/bash
#批量免密登陆(生产环境)
SERVERS="`cat /root/ip_list`"
 
function sshcopyid
{
    expect -c "
        set timeout -1;
        spawn ssh-copy-id admin@$1;
        expect {
            \"(yes/no)?\" { send \"yes\r\" }
        };
        expect {
            \"password:\" { send \"vhPRqmLZEUJ2L9WV\r\"}
        }; 
        expect eof;
    "
}

for server in $SERVERS
do
    sshcopyid $server
 
done

相关文章

Centos系统之Shell编程基础知识
从Export理解Shell环境和变量生存期
linux shell数组变量、类型及规则
Centos编程Shell基本工作原理方案
Centos操作系统编程之Shell 问答录
rsync-linux备份脚本