Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> Linux技術

SSH KEY 免密碼登錄配置步驟

準備工具

macOS 安裝 ssh-copy-id:

brew install ssh-copy-id

Linux 安裝:

yum install openssh*

Step 1:生成 SSH 公鑰

ssh-keygen -t dsa
Generating public/private dsa key pair.
Enter file in which to save the key (/root/.ssh/id_dsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_dsa.
Your public key has been saved in /root/.ssh/id_dsa.pub.

會在家目錄下生成隱藏目錄 .ssh 以及 id_dsa、id_dsa.pub 等文件。

Step 2:把公鑰複製到目標服務器

ssh-copy-id -i id_dsa.pub root@172.16.1.11

首次連接會提示確認主機真實性,輸入 yes 後再輸入目標機密碼。完成後可檢查遠端的 .ssh/authorized_keys,確認沒有多出意料之外的公鑰。

Step 3:驗證免密登錄

ssh root@172.16.1.11
Last login: Fri Jul 8 02:00:40 2016 from 172.16.1.1
[root@centos ~]#

不再提示輸入密碼,說明免密登錄配置成功。

Copyright © Linux教程網 All Rights Reserved