設定 SSH 的 RSA 驗證

最近老是有許多韓國和對岸的朋友來 try 偶的 SSH 密碼,
可能看偶的流量不速粉大,提高偶的頻寬使用率..
所以就啟動了 SSH 的 RSA 驗證機制,設定方式如下:

1. 編輯 SSH Server 設定檔 /etc/ssh/ssh_config
RSAAuthentication yes #啟動 RSA 驗證
PubkeyAuthentication yes #接受 Pubkey
AuthorizedKeysFile .ssh/authorized_keys #Pubkey 的檔名
PasswordAuthentication no #只使用 RSA 驗證(不使用密碼驗證)

2. 使用登入帳號(例如 username帳號)產生 Pubkey (不建議用 root 登入),在 username 的 home 目錄執行指令 ssh-keygen -d (若沒有.ssh目錄請先建立),過程會詢問密碼,直接按 Enter 登入 SSH 時就不會問密碼
Enter file in which to save the key (/home/username/.ssh/id_dsa) : (按Enter)
Enter passphrase (empty for no passphrase): (按Enter)
Enter same passphrase again: (按Enter)

出現下面訊息表示 Key 已經建立完成( key 請妥善保存)
Your identification has been saved in /home/username/.ssh/id_dsa. (Prikey)
Your public key has been saved in /home/username/.ssh/id_dsa.pub. (Pubkey)

3. 將 Pubkey 改名為 authorized_keys,這樣 Server 端的工作就完成了。(記得重新啟動 sshd)
#mv id_dsa.pub authorized_keys

4. 將 id_dsa 複製到 Client 端,如果使用 putty 可以用 puttygen.exe 轉成 .ppk 格式,在 putty 的 Auth\Private key file for authentication 指定 ppk 檔案,即可以直接登入 Server 。

0 意見