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

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

时间:2016-11-14 02:45:48      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:machine   please   second   密码   files   

#!/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密码,建立主机信任脚本

标签:machine   please   second   密码   files   

原文地址:http://ridingonhorse.blog.51cto.com/11265295/1872409

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