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

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了shell 练习 (免密钥登陆脚本)相关的知识,希望对你有一定的参考价值。

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

 

以上是关于shell 练习 (免密钥登陆脚本)的主要内容,如果未能解决你的问题,请参考以下文章

jenkins配置ssh免密码登陆

Shell 脚本 ssh免密码 登录 远程服务器 sshpass用法示例

shell脚本配置ssh免密登陆

centos 实现免密钥登陆

SSH密钥登陆免密码方法

jenkins执行shell脚本,使用scp免密传输失败问题