linux 批量ssh认证
2015-10-30 16:20
375 查看
<pre name="code" class="sql">redis01:/root# cd .ssh -bash: cd: .ssh: No such file or directory redis01:/root# pwd /root redis01:/root# cd .ssh redis01:/root/.ssh# ls known_hosts redis01:/root/.ssh# ls id_rsa id_rsa.pub known_hosts 自动化ssh 脚本: #root用户初始化脚本,initroot.sh if [ ! $# -eq 2 ] ;then echo "请输入用户密码以空格分开" exit else ssh-keygen -t rsa #用户名 uname="$1" #密码 passwd="$2" fi #执行检测并安装expect模块 ep=`rpm -qa | grep expect` if [ -z $ep ] ; then echo "检测到你的系统,没有安装expect模块,准备执行安装" sleep 2 yum install -y expect else echo "已经安装expect模块,3秒后,开始执行ssh文件同步" sleep 3 fi #公钥无ssh认证模块 cat hosts | while read host do echo "当前正在向$host上传输ssh文件" expect <<EOF spawn scp -r .ssh/ $host:/$uname expect { "*yes/no" {send "yes\r" ;exp_continue} "*password:" {send "$passwd\r" ;exp_continue } } EOF echo "当前正在$host上进行公钥认证....." sleep 2 expect <<EOF spawn ssh-copy-id -i .ssh/id_rsa.pub $host expect { "*yes/no" {send "yes\r" ;exp_continue} "*password:" {send "$passwd\r" ;exp_continue } } EOF echo "认证成功...." done #切换root权限进行hosts文件分发 echo "同步本机的hosts文件到各个机器上" sleep 1 #同步本机的hosts文件到其他各个机器上 cat hosts | while read host do scp -r /etc/hosts $host:/etc/ done echo "同步hosts文件完毕" A->B B-> 相互信任 A 脚本需要ssh-keygen -t rsa B不需要
相关文章推荐
- Linux Programing -- ch13-- 进程间通信:管道
- HowTo: Linux Check IDE / SATA Hard Disk Transfer Speed
- Linux pdf书本
- CentOS6.5安装GitLab全过程
- linux下创建用户,制定目录,赋权限
- linux 开启制作无线路由器(ubuntu 1404)
- Linux和bootstrap的学习总结
- 解决linux too many files问题
- Linux:ssh_config快速访问服务器
- Linux:ssh_config快速访问服务器
- Linux:alias永久生效
- Linux:alias永久生效
- Linux下从svn导出项目
- 查看Linux版本号
- Linux下安装jdk
- linux硬链接与软链接
- Linux下各路径的作用
- Linux下安装mysql
- linux 空间不够,磁盘挂载
- centos安装MSSQL PDO_DBLIB扩展