ssh免密码登录
示例:两台linux主机,主机A要免密码登录到主机B
1、准备工作
- 两台linux主机A、B(也可以是虚拟机)
2、密钥文件生成
生成A,B两机器的各自密钥文件,生成方法如下:
[root@hangzhi ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): #按回车键跳过
Created directory '/root/.ssh'.
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:AAH7q02rnbC3EFBrwhoBQuPzQ1NPRM9fnw3aQAnl/PU root@hangzhi
The key's randomart image is:
+---[RSA 2048]----+
|*oo.ooo+ .oo. |
|+o.o..o o +. |
|+++o .. o +.. .|
|.=+.. . . .=.o+|
|. .o. S .. ooE|
| ... |
| o o |
| O.o |
| +o*. |
+----[SHA256]-----+
3、配置密钥文件
示例是主机A要免密码登录到主机B,所以要在主机B的认证文件中配置主机A的密钥
在主机B上编辑/root/.ssh/authorized_keys文件, 将主机A的/root/.ssh/id_rsa.pub的密钥粘贴进去即可