#!/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





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