Linux下配置远程免密登录
第一步:
输入ssh-keygen:
[root@localhost zookeeper-3.5.7]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
/root/.ssh/id_rsa already exists.
Overwrite (y/n)? y
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:B4ItqoyaNW4Q7RMLnLCaOXSniVDyGmq/2HG7zojyBAY root@localhost.localdomain
The key's randomart image is:
+---[RSA 2048]----+
| |
|o . o |
|E*. o o . |
|B++o o . . |
|*X+o+ S . |
|%=+o . |
|++=o . |
|o==o= . |
|+=o+o=. |
+----[SHA256]-----+
先按一次回车,然后输入y,最后再回车两次即可。
第二步
到/root/.shh 目录查看是否生成了私钥和公钥:
[root@localhost zookeeper-3.5.7]# cd /root/.ssh
[root@localhost .ssh]# ls -l
总用量 16
-rw-------. 1 root root 408 3月 10 22:27 authorized_keys
-rw-------. 1 root root 1679 3月 10 22:30 id_rsa
-rw-r--r--. 1 root root 408 3月 10 22:30 id_rsa.pub
-rw-r--r--. 1 root root 348 3月 10 22:28 known_hosts
第三步
输入 ssh-copy-id 需要配置的机器的 ip 地址,然后再输入密码即可。(注:如果是第一次远程登录可能还需要再确认一下,直接输入yes即可):
[root@localhost .ssh]# ssh-copy-id 192.168.3.19
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.3.19 (192.168.3.19)' can't be established.
ECDSA key fingerprint is SHA256:umXC5dyzqoUzyZTyiPVy4q+fMxOQA42gunpHwKL2XCY.
ECDSA key fingerprint is MD5:95:a1:66:fa:70:0a:f5:38:fe:8f:9d:21:19:b8:8b:01.
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 youare prompted now it is to install the new keys
root@192.168.3.19's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh '192.168.3.19'"
and check to make sure that only the key(s) you wanted were added.
现在就可以进行免密远程登录了。

浙公网安备 33010602011771号