说明:
A为linux服务器a
B为linux服务器b
每台linux都有ssh的服务端和客户端,linux下的ssh命令就是一个客户端
我们常用ssh协议来进行登陆或者是文件的拷贝,都需要密码
A要免密登陆B:
1,需要在a中执行ssh-keygen生成自己的公钥和私钥,生成的文件在.ssh文件中。
2,需要吧a中的公钥copy到b中的中,b进行授权(把公钥中的信息拷贝到“authorized_keys”文件中) 这里只需要一个命令ssh-copy-id 命令
实际设置:
[root@mobancentos70 .ssh]# ssh-keygen
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:
b2::f8:::a3:e0:de:2e:a8::::::2b root@mobancentos70
The key's randomart image is:
+--[ RSA ]----+
|*. |
|o . |
| + |
|E .. |
|... . o S |
|.. + . + |
|O.o . . |
|B=. |
|=ooo |
+-----------------+
[root@mobancentos70 .ssh]# ssh-copy-id 172.20.13.230
/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: key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@172.20.13.230's password: Number of key(s) added: Now try logging into the machine, with: "ssh '172.20.13.230'"
and check to make sure that only the key(s) you wanted were added. [root@mobancentos70 .ssh]# ssh 172.20.13.230
Last login: Sat Mar 17 15:33:32 2018 from 10.6.196.196