linux12企业实战 -- 07ssh免密

###  一、如何做两台主机的免密

源主机Ip 目标Ip 备注
192.168.10.11 192.168.10.111
172.16.1.11 172.16.1.111

1.登录主机Ip做免密

[root@test ~]# ssh-keygen 
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
/root/.ssh/id_rsa alreadyexists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Saving key "/root/.ssh/id_rsa" failed: Permission denied

linux12企业实战 -- 07ssh免密_第1张图片

[root@test ~]# lsattr .ssh/
----i----------- .ssh/id_rsa
----i----------- .ssh/id_rsa.pub
[root@test ~]# chattr -i .ssh/*
[root@test ~]# lsattr .ssh/
---------------- .ssh/id_rsa
---------------- .ssh/id_rsa.pub

linux12企业实战 -- 07ssh免密_第2张图片

2、源主机做免密成功

[root@test ~]# ssh-keygen 
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
/root/.ssh/id_rsa already exists.
Overwrite (y/n)? y
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:NNGQ8NivA/kfzRjY7EBpZj9kSybMM/GMc0G7vT0k50E root@test
The key's randomart image is:
+---[RSA 2048]----+
|      ..+=o      |
|       *.B.o     |
|      . ^ X   E  |
|       B ^ + .   |
|      o S X o +  |
|       o + * B . |
|        + + + +  |
|         o .   . |
|          .      |
+----[SHA256]-----+

3、把源主机的公钥复制到目标主机上

[root@test02 ~]# vim .ssh/authorized_keys 
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCcXHonxcqUJCXsmCUSfGlRX6V1jWjn/t8Dbl8GkR2DJakIHiYJvs3kJ++Yb/OzPukkK2wsEVKvLNJtbLYnxRwpJeSPCGjuZuhTiLFS19zZ/liYFwBCrbxsmNh1fcXaMmqHSwH0rfeWO3JuXQFUl/Zp9bxtay79iC5V/imH6zhOTkGpHU0gZwE2zq62Qvxm6v3R6KIulO2YzVLmkJHPMENt1ePhdWymtN5XMjpi4qldzdZet2LWUPWoeIJfeAfdirtpnmAP3K1IFjMEIONdsgRVt4ef2AOc2U5XBFf78ElGV/AuFD68t6SBAhfAbZVoCldznCeuk6XIgruASpF2HErd root@test02
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC0RmkFNX1izJGg+LpBFBwOhABrX0OJcIg7JDBoK+TPi68hJWah0eV9/g6GYRMqQ922O72tGzhgLzxGNrR816eJ46fdY8Ui1W2R28Rwc/dj+egSScaHUm+aAyDZqkCKTqwRe3+Tp3zJaqmH/covXe+PDVm63xtZfXc7gdwT+yyU1zkYzlRvKJ3tGlovHrNBCAbLVUyMQLlPjy3Ea4rENXce3OAv6CXhZmFZm/2wQfcs73Ok9WptIqv2lKr8b6r8sjxZWazA9nijEVP+QhwDbuBPKUMzx9mo2X7fHGLeDZwckb4daT95iMnu750pJVAGr4UKRfXJBYr9fmpSPpiHh/zP root@test

linux12企业实战 -- 07ssh免密_第3张图片

4、验证结果

[root@test ~]# ssh 172.16.1.111
Last login: Thu Oct 14 16:10:06 2021 from 172.16.1.11
[root@test02 ~]# 

linux12企业实战 -- 07ssh免密_第4张图片

你可能感兴趣的:(linux12,--,企业实战,ssh,linux)