Linux设置ssh免密登录
Linux设置ssh免密登录
创建本机公钥和私钥
[root@hdss7-200 ~]# 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:ai8hg3aMQTCR5fJfKADLG05fbEBYqR6k2QkzqyPelAg root@hdss7-200.host.com
The key's randomart image is:
+---[RSA 2048]----+
|===+. |
|B*..o |
|*%o. + |
|E*B o. |
|+o=*o . S |
|+o+==... |
|ooo..oo. |
| . . ... |
| .. |
+----[SHA256]-----+
将公钥传到你需要免密访问的服务器上,本机将用私钥去匹配远端服务器上的公钥,匹配上即可免密通信
[root@hdss7-200 ~]# ssh-copy-id root@hdss7-11 #hdss7-11为短域名,可替换成远端服务器的IP
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host 'hdss7-11 (10.4.7.11)' can't be established.
ECDSA key fingerprint is SHA256:HAAyom2+r6UQgWJZimJNMf18jL6HvhjC2Ytmvk/OkUo.
ECDSA key fingerprint is MD5:da:a1:ee:bc:d8:6d:3a:f2:2d:ae:f0:b3:c3:dd:59:60.
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@hdss7-11's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@hdss7-11'"
and check to make sure that only the key(s) you wanted were added.
难走的路才是上坡路,好走的路都是下坡路!

浙公网安备 33010602011771号