问题
I am attempting to do a simple connection to a SSH server using OpenSSH for Windows using a private key, and am met with this:
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: UNPROTECTED PRIVATE KEY FILE! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions for 'private' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
Load key "private": bad permissions
On Linux, this is fixed with a simple chmod 600 on the private key file, however Windows does not have an equivalent method.
This sounds like something that should be pretty easy, but I am completely unable to find any reasonable solution to it. Is there a way to either add the private key directly without going through a file, or to skip this privacy check? Or am I missing something else entierly?
回答1:
You can use icacls in windows instead of chmod to adjust file permission. To give the current user read permission and remove everything else (Which will allow openssh to work), this works nicely:
icacls .\private.key /inheritance:r
icacls .\private.key /grant:r "%username%":"(R)"
回答2:
If we are still looking the solution of the SSH problem:
- Go to your private key and add the root user(make sure you are adding the owner of the computer) of your computer and provide full rights.
- Remove the other users.
If we are not able to remove the users
- Go to the security tab in Properties tab and click on Advanced
- In next screen there will be a Disable Inheritance button click on that.
- It will open a popup and select the first option(Convert inherited permissions..) and then try removing.
In my issue, I was trying to connect ec2.prem file which is a private key to AWS and after following above steps, I was able to resolve it.
Happy Coding :)
回答3:
You locate the file in Windows Explorer, right-click on it then select "Properties". Navigate to the "Security" tab and click "Advanced".
Change the owner to you, disable inheritance and delete all permissions. Then grant yourself "Full control" and save the permissions. Now SSH won't complain about file permission too open anymore.
来源:https://stackoverflow.com/questions/48888365/openssh-using-private-key-on-windows-unprotected-private-key-file-error