linux12企业实战 -- 07ssh免密
Posted FikL-09-19
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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
[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
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
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免密的主要内容,如果未能解决你的问题,请参考以下文章