码迷,mamicode.com
首页 > 系统相关 > 详细

shell 练习 (免密钥登陆脚本)

时间:2018-03-08 23:02:52      阅读:326      评论:0      收藏:0      [点我收藏+]

标签:adc   ons   word   author   shel   close   lease   4.0   back   

#!/bin/bash
remote_ip=$1 if [ ! -n "$1" ] ;then echo "please usage ./without_password remote_host!" exit 1 else echo "the remote_host you input is $remote_ip" fi ssh root@$remote_ip "mkdir .ssh; chmod 700 .ssh" ssh-keygen -t rsa scp ~/.ssh/id_rsa.pub root@10.0.0.223:/root/.ssh/authorized_keys ssh root@$1 "chmod 600 ~/.ssh/authorized_keys" ssh root@$1 ifconfig

退出远程

[root@localhost ~]# exit
logout
Connection to 10.0.0.223 closed.
eth0      Link encap:Ethernet  HWaddr 00:0C:29:DD:80:F9  
          inet addr:10.0.0.50  Bcast:10.255.255.255  Mask:255.0.0.0
          inet6 addr: fe80::20c:29ff:fedd:80f9/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:9826 errors:0 dropped:0 overruns:0 frame:0
          TX packets:6413 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:985311 (962.2 KiB)  TX bytes:915545 (894.0 KiB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:155 errors:0 dropped:0 overruns:0 frame:0
          TX packets:155 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:16942 (16.5 KiB)  TX bytes:16942 (16.5 KiB)

 

shell 练习 (免密钥登陆脚本)

标签:adc   ons   word   author   shel   close   lease   4.0   back   

原文地址:https://www.cnblogs.com/benjamin77/p/8531172.html

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