![如何在 Windows 10 上保護 SSH 私鑰](https://rvso.com/image/1557249/%E5%A6%82%E4%BD%95%E5%9C%A8%20Windows%2010%20%E4%B8%8A%E4%BF%9D%E8%AD%B7%20SSH%20%E7%A7%81%E9%91%B0.png)
我正在使用 Windows 10 的新 ssh 用戶端,當嘗試使用私鑰連線時,我收到此錯誤:
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: UNPROTECTED PRIVATE KEY FILE! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions for 'MyPair.pem' are too open. It is required that your
private key files are NOT accessible by others. This private key will
be ignored. Load key "MyPair.pem": bad permissions [email protected]:
Permission denied (publickey).
我知道如果我在 Linux 上,我需要運行chmod 600
來設定檔案權限,但是你在 Windows 10 上使用什麼?
答案1
金鑰必須只能由其目標使用者訪問,而其他帳戶、服務或群組不能存取。
- 圖形使用者介面:
[文件]特性→安全→先進的- 所有者:改變 →選擇校長→ 輸入金鑰的使用者 → 決定
- 權限條目:刪除密鑰用戶之外的所有內容
- 將密鑰的使用者設定為完全控制如果尚未設定
- 選擇使用者→修改→完全控制→確定
或者 - 添加 →選擇校長→ 輸入金鑰的使用者 → 決定
- 選擇使用者→修改→完全控制→確定
- 好→好
Cmd
:::# Set Key File Variable: Set Key="%UserProfile%\.ssh\id_rsa" ::# Remove Inheritance: Icacls %Key% /c /t /Inheritance:d ::# Set Ownership to Owner: Icacls %Key% /c /t /Grant %UserName%:F ::# Remove All Users, except for Owner: Icacls %Key% /c /t /Remove Administrator BUILTIN\Administrators BUILTIN Everyone System Users ::# Verify: Icacls %Key% ::# Remove Variable: set "Key="
PowerShell
:# Set Key File Variable: New-Variable -Name Key -Value "$env:UserProfile\.ssh\id_rsa" # Remove Inheritance: Icacls $Key /c /t /Inheritance:d # Set Ownership to Owner: Icacls $Key /c /t /Grant $env:UserName:F # Remove All Users, except for Owner: Icacls $Key /c /t /Remove Administrator BUILTIN\Administrators BUILTIN Everyone System Users # Verify: Icacls $Key # Remove Variable: Remove-Variable -Name Key
- WSL/Cygwin:
# Set Variables: # Key File: key="/path/to/key" # User: user="$(echo $USER)" # Set Ownership to Owner: (assumes user's name is also user's group name) chown $user:$user $key # Set Access Rights chmod 0600 $key # Verify ls -l $key
答案2
使用 Windows 10 GUI,以下是一些其他詳細資訊:
- 右鍵單擊pem文件,屬性,安全性。
- 將所有者設定為金鑰的使用者(即您)
- 權限條目,刪除密鑰使用者以外的所有使用者、群組、服務
- 將密鑰的使用者設定為「完全控制」。我是這樣做的:
- 禁用繼承。如果您看到彈出窗口,請選擇轉換為對此文件的明確權限。
- 新增,選擇主體,物件類型為 User,物件名稱為 key 擁有者的使用者名稱(例如,如果您的主目錄是 c:\Users\ben 資料夾,則在此處鍵入 ben)。好的。
- 給予該用戶完全控制權
- 刪除其他所有人(經過驗證的使用者、系統等)
- 好的
在停用繼承之前,將擁有者設定為金鑰的使用者非常重要。
答案3
為了節省時間,比其他解決方案容易得多:只需將檔案移至磁碟機上的“安全位置”,例如資料夾%userprofile%/.ssh
。
注意:有些人說它在 C: 驅動器或用戶的下載資料夾上的任何地方都可以工作,但我沒有對此進行測試。