Windows-SSH--Permissions-for-'private-key'-are-too-open

  1. 在Win中OpenSSH使用密钥登录时全出现权限错误
C:\>ssh root@192.168.1.55 -i key.pem
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions for 'key.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 "key.pem": bad permissions
root@192.168.1.55: Permission denied (publickey).
  1. 这是权限问题,如果在linux或mac系统中,直接用chmod 600 key.pem
  2. 在Win中用icacls命令,下面写个bat脚本
:: # Set Variable ::
Set Key=%1

:: # Remove Inheritance ::
Cmd /c Icacls %Key% /c /t /Inheritance:d

:: # Set Ownership to Owner ::
Cmd /c Icacls %Key% /c /t /Grant %UserName%:F

:: # Remove All Users, except for Owner ::
Cmd /c Icacls %Key% /c /t /Remove Administrator "Authenticated Users" BUILTIN\Administrators BUILTIN Everyone System Users

:: # Verify ::
Cmd /c Icacls %Key%
  1. 将key.pem直接托到bat脚本上运行就行了

本文参考:https://superuser.com/questions/1296024/windows-ssh-permissions-for-private-key-are-too-open

0%