运维开发网

ssh判断免密登陆

运维开发网 https://www.qedev.com 2021-04-17 18:03 出处:51CTO 作者:80民工
ssh判断免密登陆 [root@jenkins ~]# vi /opt/release_code.sh #!/bin/bash . /etc/init.d/functions #echo $WORKSPACE #echo $JOB_NAME Remote_IP="10.0.0.7" ssh $Rem

ssh判断免密登陆

[root@jenkins ~]# vi /opt/release_code.sh
#!/bin/bash

. /etc/init.d/functions

#echo $WORKSPACE
#echo $JOB_NAME

Remote_IP="10.0.0.7"

ssh $Remote_IP -o PreferredAuthentications=publickey -o StrictHostKeyChecking=no "ls" &> /dev/null

if [ $? -eq 0 ]; then
    action  "目标主机免密连接正常" /bin/true
else
    echo
    echo -e "*******免密失败,分发密钥*******\n"
    sshpass -p1 ssh-copy-id -i ~/.ssh/id_rsa.pub root@$Remote_IP -o StrictHostKeyChecking=no &>/dev/null
    if [ $? -eq 0 ];then
        action "$Remote_IP : 密钥分发成功" /bin/true
        echo
    else
        action "$Remote_IP : 密钥分发失败" /bin/false
        echo
    fi
fi
0

精彩评论

暂无评论...
验证码 换一张
取 消