[root@es-node1 .ssh]# ssh-keygen -t rsa 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: SHA256:9FmE70cLjCJTIvnMVnCMTTXjgywgGmFOLYC76g432m0 root@es-node1 The key's randomart image is: +---[RSA 2048]----+ |*+o ...*o.+.. | |=+ oo.oo=o.+ | |.o. =.++ o+. | |. Bo...++ . | | . . oS.o. o . | |. . o | |o o . | |o+ oE | |+o... | +----[SHA256]-----+
[root@es-node1 .ssh]# ssh-copy-id -i ./id_rsa.pub root@es-node2 /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "./id_rsa.pub" /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@es-node2's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@es-node2'" and check to make sure that only the key(s) you wanted were added.