zoukankan      html  css  js  c++  java
  • 自动添加 ssh key 到远程主机的脚本,应用sshpass和ssh-copy-id

    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
  • 相关阅读:
    171-滑动窗口问题
    170-133. 克隆图
    169-150. 逆波兰表达式求值
    windows相对路径设置与取消小工具[提效]
    Sword 38
    Sword 33
    Sword 28
    Sword 26
    Sword 12
    Sword 07
  • 原文地址:https://www.cnblogs.com/pekkle/p/10845749.html
Copyright © 2011-2022 走看看