思路:
#step1:生成秘鑰 生成以后我這里保存在 /root/.ssh/id_rsa 記住這個位置 ssh-keygen #敲3次回車 #將秘鑰發送到另一台linux服務器 此過程會輸入免密登錄的linux用戶密碼 ssh-copy-id <username>@10.1.71.51 #執行ssh命令進行登錄 ssh <username>@10.1.71.51
具體操作:
step1:生成密鑰
ssh-keygen

step2:將秘鑰發送到另一台linux服務器,
系統詢問是否繼續連接時,輸入yes
然后輸入root用戶的密碼
(ssh <username>@10.1.71.51)你使用的是哪個username,就輸入哪個username的登錄密碼)
wangju@wangju-HP-348-G4:~$ ssh-copy-id root@10.2.1.92 The authenticity of host '10.2.1.92 (10.2.1.92)' can't be established.
ECDSA key fingerprint is SHA256:Ar7EcI1o7lTpJNX7dD3FgDKyV7180t2iAGjXrjBlBGU. 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@10.2.1.92's password: Number of key(s) added: 1 Now try logging into the machine, with: "ssh 'root@10.2.1.92'" and check to make sure that only the key(s) you wanted were added.
step3:驗證配置結果:
再次執行 ssh root@10.2.1.92,不需要再輸入密碼,即可連接成功
wangju@wangju-HP-348-G4:~$ ssh root@10.2.1.92 Last login: Fri Jan 3 15:59:31 2020 from 10.1.71.32 [root@67 ~]# logout Connection to 10.2.1.92 closed.
