'OpenSSH using private key on Windows ("Unprotected private key file" error)
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?
Solution 1:[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:
Command Prompt:
icacls .\private.key /inheritance:r
icacls .\private.key /grant:r "%username%":"(R)"
In PowerShell, you can get icacls
to work by wrapping the command in a call to cmd.exe
icacls .\private.key /inheritance:r
start-process "icacls.exe" -ArgumentList '.\private.key /grant:r "$env:USERNAME":"(R)"'
Solution 2:[2]
FYI: Rename the "test.pem" to your original pem file name.
Setting path variable
$path = ".\test.pem"
Reset to remove explicit permissions
icacls.exe $path /reset
Give current user explicit read-permission
icacls.exe $path /GRANT:R "$($env:USERNAME):(R)"
Disable inheritance and remove inherited permissions
icacls.exe $path /inheritance:r
Note:
- You can replace the file name as per your file name. In this case it is test.pem.
- You must be in the same directory where your file is located.
- You must open power shell as administrator.
Solution 3:[3]
I did it on Windows 10 and it fixed the issue as you can see in the image as well.
You should change the owner of the file(which contains the private key)to your username with full access. and then remove the other usernames that have access to that file.
right-click on the file which contains the private key and clicks on properties and then Security tab> Advanced by clicking on the change button you can change the owner to your username. (if you don't know the name of your username run: "echo %USERNAME%" in command prompt.) Change>Advanced...>Find Now
remove all Permission entries except the one you just added
click on Disable inheritance> Convert inherited permissions... then remove all Permission entries except the one you just added.
Solution 4:[4]
For windows 10 store the key file in User Ex: C:\Users\MANNEM.ssh
Make sure permission of private key file will be as shown in the image
Solution 5:[5]
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.
Solution 6:[6]
i had the same error on windows, but after moving the private key file to "C:\Users\Administrator.ssh" it works fine
Solution 7:[7]
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.
Solution 8:[8]
I tried changing permission but that didn't work. What worked for me was changing the ownership to current user, as the key was created by other Admin user
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Aamnah |
Solution 2 | ouflak |
Solution 3 | pedram |
Solution 4 | mannem srinivas |
Solution 5 | Shraddha J |
Solution 6 | MedMahmoud |
Solution 7 | Tomerikoo |
Solution 8 | PatrickBateman92 |