#!/bin/bash ###通过配置 nopass.config ,实现与多服务器的免密登录 [ ! -f $HOME/.ssh/id_rsa ] && ssh-keygen -t rsa -b 2048 -N "" -f $HOME/.ssh/id_rsa if ! grep -Ff $HOME/.ssh/id_rsa.pub $HOME/.ssh/authorized_keys &>/dev/null; then cat $HOME/.ssh/id_rsa.pub >>$HOME/.ssh/authorized_keys fi chmod 600 $HOME/.ssh/authorized_keys for ip in $(awk '/^[0-9]/{print $1}' nopass.config | sort -u); do # ssh-copy-id -o StrictHostKeyChecking=no -o CheckHostIP=no root@$ip rsync -a $HOME/.ssh/id_rsa* $HOME/.ssh/authorized_keys -e 'ssh -p 2009 -o StrictHostKeyChecking=no -o CheckHostIP=no' mmog@$ip:/home/mmog/.ssh/ let ret+=$? done