linux_ssh_免密登录

现在有两台linux机器A 及 linux机器B   想实现A连接B时免密能够登录

在linuxA上生成ssh的key (一顿回车)

[root@mylinuxA ~]# ssh-keygen -t rsa
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:dqsdN10xhgaXC7lA/Zrm2pE0Iwzi4eOVBi3DdN7y3rE root@qbsea
The key's randomart image is:
+---[RSA 2048]----+
|     . ........  |
|    o + .. +o..  |
|     B = .. +o.+ |
|    o * *  ..o. o|
|     + +S+.=o   .|
|    . +...+=*. . |
|     .   .=Eo .  |
|         o.+..   |
|        ..o.     |
+----[SHA256]-----+

然后会在/root/.ssh 目录下多两个文件 id_rsa 及 id_rsa.pub

在linuxA上通过id_rsa.pub来连接linuxB

ssh-copy-id -i /root/.ssh/id_rsa.pub [email protected]   (到时需要知道10.17.x.myLinuxB的密码)

[root@mylinuxA ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub [email protected]
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '10.17.x.myLinuxB (10.17.x.myLinuxB)' can't be established.
RSA key fingerprint is SHA256:15+g1FpULiX6nMmwF6mzhge3BegNIl6tzBRq6gS+f60.
RSA key fingerprint is MD5:e6:c2:0d:bc:20:63:33:b9:b2:94:cc:9b:8c:5c:a0:3b.
Are you sure you want to continue connecting (yes/no)? yes
/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 keys
[email protected]'s password: ##录入密码

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh '[email protected]'"
and check to make sure that only the key(s) you wanted were added.

执行成功后 登录LinuxB 机器的/root/.ssh   然后执行 cat authorized_keys

就证明 A成功的能免密的连接了B

猜你喜欢

转载自blog.csdn.net/maqingbin8888/article/details/86589719