码迷,mamicode.com
首页 > 其他好文 > 详细

自动添加 ssh key 到远程主机的脚本,应用sshpass和ssh-copy-id

时间:2019-05-10 17:58:06      阅读:168      评论:0      收藏:0      [点我收藏+]

标签:lse   ssi   主机   style   missing   use   pre   col   sshpass   

 

 

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

 

自动添加 ssh key 到远程主机的脚本,应用sshpass和ssh-copy-id

标签:lse   ssi   主机   style   missing   use   pre   col   sshpass   

原文地址:https://www.cnblogs.com/pekkle/p/10845749.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!