模擬場景:192.168.1.5服務器上配置,通過ssh遠程免密登錄192.168.1.160 1、安裝SSH,此處省略 2、生成公鑰和私鑰,生成的秘鑰默認在/root/.ssh/文件夾里面 [root@localhost ~ 09:16:45&&26]# ssh-keygen #默認按enter直至結束 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:2GM5hi5CJhi+6JbmYkHfbbnNzYB3FoFUr+D50gGt9KQ root@localhost.localdomain The key's randomart image is: +---[RSA 2048]----+ | ..o. | | .... | |. + o.. | |oo +o.O.. | |+.+ . + SE +. | |.=.. o B =oo. | |..+ . o =.*o | |o= . . . o.o | |*o | +----[SHA256]-----+ 3、把生成的公鑰發送到對方的主機上去,用ssh-copy-id命令,自動保存在對方主機的/root/.ssh/authorized_keys文件中去 [root@localhost ~ 09:16:45&&26]# ssh 192.168.1.160 #需要登錄密碼 [root@localhost ~ 09:16:45&&26]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.1.160 [root@localhost ~ 09:16:45&&26]# ssh 192.168.1.160 #免密登錄
