SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。
USERNAME=$1
PASSWORD=$2
HOST=$3

if [ "$3" = "" ]; then
  echo "Missing parameter 3 - host. Exit."
  exit 1
fi

if [ "$2" = "" ]; then
  echo "Missing parameter 2 - password. Exit."
  exit 1
fi

if [ "$1" = "" ]; then
  echo "Missing parameter 1 - username. Exit."
  exit 1
fi

if [ -f ~/.ssh/config ]; then
    grep StrictHostKeyChecking ~/.ssh/config
    exist=`echo $?`
    
    if [ ! "$exist" = "0" ]; then
      echo StrictHostKeyChecking no >> ~/.ssh/config
    fi
else
  echo StrictHostKeyChecking no >> ~/.ssh/config
fi

sshpass -p ${PASSWORD} ssh-copy-id -i ~/.ssh/id_rsa.pub ${USERNAME}@${HOST}

result=`echo $?`

if [ "$result" = "0" ]; then
  echo "Host ${HOST} is configured successfully."
else
  echo "Host ${HOST} configure failed."
fi

 

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄