Linux免密登陆

2020-08-14 16:35:44 浏览数 (1)

参考

Linux机器之间免密登录设置

1. 配置两台Linux服务器,均为Centos7

master: 192.168.1.89 node: 192.168.1.65

2. master生成ssh密钥

ssh-keygen -t rsa

一路回车

代码语言:javascript复制
[root@bogon .ssh]# ssh-keygen -t rsa
Generating 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:U He9vxeISDtG2nT5EZULBNrQAJtn4b2HUcFX3Gi7bg root@bogon
The key's randomart image is:
 ---[RSA 2048]---- 
|       .o.oo o* *|
|          o.o=.=o|
|        ..=oo== .|
|         =o=O  . |
|        S  *== . |
|         ..o==. .|
|           .E o .|
|               ..|
|               .o|
 ----[SHA256]----- 

3. 查看master生成的公钥私钥

在~/.ssh文件夹下,有id_rsa、id_rsa.pub两个文件

代码语言:javascript复制
* id_rsa : 生成的私钥文件 *
* id_rsa.pub : 生成的公钥文件*

4. 复制公钥文件到node服务器上并重命名为authorized_keys

在master上使用 ssh-copy-id 命令

ssh-copy-id -i ~/.ssh/id_rsa.pub 192.168.1.65

5. master首次远程node

代码语言:javascript复制
[root@bogon .ssh]# ssh 192.168.1.65
The authenticity of host '192.168.1.65 (192.168.1.65)' can't be established.
ECDSA key fingerprint is SHA256:JHXcH2MD3f7NaTDe0FGeC8liVsJwD LuOSWgjXI9Pzo.
ECDSA key fingerprint is MD5:48:55:78:07:c9:d2:0b:5b:74:cc:e1:71:6e:5e:eb:f1.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.65' (ECDSA) to the list of known hosts.
Last login: Tue Aug  4 14:22:50 2020 from 192.168.1.89

6. master再次远程node的时候可直接登录

代码语言:javascript复制
[root@bogon .ssh]# ssh 192.168.1.65
Last login: Tue Aug  4 14:32:40 2020 from 192.168.1.89

0 人点赞