博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
设置Linux主机免密认证
阅读量:4188 次
发布时间:2019-05-26

本文共 1799 字,大约阅读时间需要 5 分钟。

1、生成公钥

首先检查主机是否存在公钥:

进入./ssh目录,查询是否存在 id_rsa 和 id_rsa.pub(公钥)。

[root@server1 ~]# cd .ssh/[root@server1 .ssh]# ll总用量 16-rw-r--r-- 1 root root  802 5月  22 10:35 authorized_keys-rw------- 1 root root 1675 5月  22 10:34 id_rsa-rw-r--r-- 1 root root  394 5月  22 10:34 id_rsa.pub-rw-r--r-- 1 root root  522 5月  20 16:31 known_hosts

如果公钥不存在,需要生成公钥:

使用命令 ssh-keygen 生成公钥,在后续的回显中一路Enter

[root@host199 ~]# ssh-keygenGenerating public/private rsa key pair.Enter file in which to save the key (/root/.ssh/id_rsa):Enter passphrase (empty for no passphrase):Enter same passphrase again:Your identification has been saved in /root/.ssh/id_rsa.Your public key has been saved in /root/.ssh/id_rsa.pub.The key fingerprint is:SHA256:2CQOB8XnJktJnasdTcTr2J9fI9k4iZufr0tJfUBnK9s root@host199The key's randomart image is:+---[RSA 2048]----+|    .o.. +.   . o||     .o + o  . o.||    ..o+.+ . ... ||     ++== o   =. ||     .o*S=   o E.||      o o o o * .||           o X o.||            * +..||           o.*=. |+----[SHA256]-----+

 

2、对目标主机设置免密

使用命令 ssh-copy-id <ip> 对目标主机设置免密。ip为目标主机的ip。

命令回显需输入目标主机的密码。

[root@host199 ~]# ssh-copy-id 10.1.104.188/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keysroot@10.1.104.188's password:Number of key(s) added: 1Now try logging into the machine, with:   "ssh '10.1.104.188'"and check to make sure that only the key(s) you wanted were added.

此时,主机10.1.104.188对当前主机免密。

使用ssh测试一下:

[root@host199 ~]# ssh root@10.1.104.188Last login: Thu May 28 18:53:33 2020 from 10.2.3.200[root@server1 ~]#

 

⚠️ 注意:如果要实现双向免密,需要在目标主机上重复操作一次即可。

转载地址:http://wdsoi.baihongyu.com/

你可能感兴趣的文章
在easyjweb应用中关于acegi安全配置的增强
查看>>
使用权限标签控制View层展示的内容
查看>>
5月26开源沙龙活动小记
查看>>
使用JPA+Spring2.0+EasyJWeb开发企业级应用
查看>>
5月26日北京开源沙龙活动通知
查看>>
EasyJF第一次网下交流会成功召开
查看>>
EasyJWeb、RoR、JSF&Struts2,谁更Easy?
查看>>
spring源码分析-XmlBeanFactory导读
查看>>
英雄会的郁闷与收获
查看>>
一个开源组织者的感言2
查看>>
为何不使用spring、struts2、easyjweb等开源框架
查看>>
Eclipse 误删文件怎么办
查看>>
EasyJF开源从网上走到网下
查看>>
让spring帮助你在MVC层解决JPA的缓迟加载问题
查看>>
在EasyJWeb使用spring容器
查看>>
EasyJWeb中灵活的多国语言支持
查看>>
理想·环境·开源
查看>>
EasyJWeb中缺省URL映射转换器揭密
查看>>
EasyJWeb+prototype
查看>>
EasyJF开源重组见闻-1
查看>>