Linux设置免密登录

1、先生成公钥。

[root@k8s-master ~]# 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:
f5:21:e0:89:44:97:1f:e5:df:71:4f:b0:3a:ec:70:31 root@k8s-master
The key's randomart image is:
+--[ RSA 2048]----+
|     .o o. .. .  |
|     . +.o..   o |
|      . o.o.E ..o|
|         ..+ * o+|
|        S . * . o|
|           + .   |
|            .    |
|                 |
|                 |
+-----------------+

 2、传输公钥到另一台机器。

[root@k8s-master ~]# ssh-copy-id 192.168.43.3      # 另一台服务的IP地址
The authenticity of host '192.168.43.3 (192.168.43.3)' can't be established.
ECDSA key fingerprint is e9:b9:0c:d9:13:ef:c7:12:ee:2a:cf:06:16:3d:da:26.
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
root@192.168.43.3's password: 

Number of key(s) added: 1

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

3、进行登录,然后退出

[root@k8s-master ~]# ssh 192.168.43.3
Last login: Fri Mar 17 00:28:31 2023 from 192.168.43.2
[root@k8s-node01 ~]# exit
logout
Connection to 192.168.43.3 closed.
posted @ 2023-03-17 15:31  持之以道  阅读(64)  评论(0编辑  收藏  举报