#!/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 [email protected]$remote_ip "mkdir .ssh; chmod 700 .ssh" ssh-keygen -t rsa scp ~/.ssh/id_rsa.pub [email protected]10.0.0.223:/root/.ssh/authorized_keys ssh [email protected]$1 "chmod 600 ~/.ssh/authorized_keys" ssh [email protected]$1 ifconfig
退出远程
[[email protected] ~]# 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)