zl程序教程

您现在的位置是:首页 >  后端

当前栏目

ssh免密配置

ssh配置 免密
2023-06-13 09:12:48 时间

# 1.生成密钥私钥

[root@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:
SHA256:NetuQCC4DHoQPQEPDD5rGOpva3vMWMobhk9GFUnwpAM root@master
The key's randomart image is:
+---[RSA 2048]----+
|BE.+o+.          |
|++= =.o          |
|o*.= + .  o      |
|+.* o   .. o     |
|o+ .   .S .      |
|o o  .  ..       |
| o.=*    ..      |
|  **.+   ..      |
|  o*=    ..      |
+----[SHA256]-----+

# 2.上传对方服务器

[root@master ~]# ssh-copy-id 192.168.0.88
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.0.88 (192.168.0.88)' can't be established.
ECDSA key fingerprint is SHA256:ZPLS5x78pbuuMIecl+HWHeDSkeG3aF6atbWZrvTSgyc.
ECDSA key fingerprint is MD5:fb:cd:88:c9:59:c9:c6:da:c5:32:15:5c:63:5f:ea:41.
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.0.88's password: 

Number of key(s) added: 1

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