首页 > 代码库 > 输入ip密码,建立主机信任脚本

输入ip密码,建立主机信任脚本

#!/bin/bash


# Date: 2015.11.13

# Description: first,build the need files,second push to the machine. 

#              you need to input your host ip

# Version: 0.0.1

echo "the mine key will come to"

[ ! -f /root/.ssh/id_rsa ] && ssh-keygen -t rsa -f ~/.ssh/id_rsa -N ‘‘

[ -f /root/.ssh/id_rsa.pub ] && cat /root/.ssh/id_rsa.pub > /root/.ssh/authorized_keys && chmod 600 /root/.ssh/authorized_keys

while true

do

        read -p "please input the host (you want to login):  "       HOST

        echo "$HOST"|egrep  ‘\<([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\>‘ || echo "the ip has problems" || exit 1

        ssh root@"$HOST" "test ! -d /root/.ssh && mkdir /root/.ssh && chmod 700 /root/.ssh"

        scp -p /root/.ssh/{id_rsa,authorized_keys} root@"$HOST":/root/.ssh

done





# 感觉脚本写的挺蹩脚,下次加油!

本文出自 “Linux” 博客,请务必保留此出处http://ridingonhorse.blog.51cto.com/11265295/1872409

输入ip密码,建立主机信任脚本