SSH无密码验证登录服务器

这种方法多用于制作自动化脚本,减少用户交互信息时使用的一种技巧

环境: 10.10.10.10 A服务器 Redhat6.4 当前用户:root xiaozhang
10.10.10.11 B服务器 Redhat6.4 当前用户:root yezi

前提要求:
1,必须知道各个用户的当前密码
2,当前能够SSH远程链接到各个用户

案例一:A服务器链接B服务器root设置为不需要输入密码即可连接
[root@A ~]# ssh-keygen -t rsa -P "" #创建一个公私钥,类型为rsa,密码为空
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 回车
[root@A ~]# ssh-copy-id root@10.10.10.11 #输入需要免密码登陆的用户名及主机IP
The authenticity of host '10.10.10.11 (10.10.10.11)' can't be established.
RSA key fingerprint is f2:ac:ea:f1:0c:80:4e:dd:44:17:5a:06:a7:89:00:ef.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.10.10.11' (RSA) to the list of known hosts.
root@10.10.10.11's password: #此处输入当前B服务器root的密码
Now try logging into the machine, with "ssh 'root@10.10.10.11'", and check in:

.ssh/authorized_keys

to make sure we haven't added extra keys that you weren't expecting.

[root@A ~]# ssh root@10.10.10.11 #链接B服务器,会发现无需输入密码
Last login: Wed Mar 8 19:03:17 2017 from 10.0.0.1
[root@B ~]#


案例二:A服务器远程B服务器的yezi身份进行登陆(yezi在A服务器是不存在该用户的)
[root@A ~]# ssh-keygen -t rsa -P "" #创建一个公私钥,类型为rsa,密码为空
Enter file in which to save the key (/root/.ssh/id_rsa): 回车
[root@A ~]# ssh-copy-id yezi@10.10.10.11 #输入需要免密码登陆的用户名及主机IP
yezi@10.10.10.11's password: #此处输入当前B服务器yezi的密码
[root@A ~]# ssh yezi@10.10.10.11 #链接B服务器,会发现无需输入密码
[root@B ~]#

过程非常的简单,一共就四个步骤,如果你的系统没有ssh-copy-id,请安装openssh-client




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值