3

I don't only ask (and answer) how to change permissions on Windows because the reason I want to do after about 20 years of Windows usage is kind of special. I am now a Winux user, running Ubuntu (WSL) on my Windows10 machine, and I publish this here also for the Winux community.

The problem I encounter:

I have an OpenSSH private key I use to login to my VPS from Linux environments.

I store this key somewhere inside Windows (hence under /mnt/c). I store it there as a backup.

In WSL I came to tunnel both port 22 and port 80 of my server, via this command:

ssh usual-user@1.1.1.1 -L 22:localhost:22 -L 2222:localhost:80 -i /mnt/c/location/private_key_file_name

I then got:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

Permissions 0777 for '/mnt/c/location/private_key_file_name' are too open.

It is required that your private key files are NOT accessible by others.

This private key will be ignored.

bad permissions: ignore key: /mnt/c/location/private_key_file_name
Permission denied (publickey).

I never had a similar problem when using Putty but nevertheless I use Putty, I still want to change permissions by principle, as well as to use the key with OpenSSH.

I seem to not be able to do chmod 600 on the private key file, on the relevant location (it changes but it then autochanges back to 777).

Given windows doesn't give you a Linux-like GUI to change permissions I believed I needed to find a way to do so from CMD. One can ask "How could I change permissions for a file in Windows, so it would be equivalent to Linux permissions".

After reading about changing permission in Windows in a Linux like way I got to the conclusion that the simplest fastest way would be to just do mv file ~, chmod 600 ~/file, and then mv file /mnt/c/location but this failed me as the moment I moved the file, it changed back to 777.

Here's my answer:

2

As I get this with my humble knowledge on this, Windows will always translate the permissions of the file to those common in Windows. This isn't necissarily problematic given that Windows has a different security model then Linux and if you use a strong Windows password to defend your files and are protected under Windows defender (which includes a firewall, IIBA, a brute force attack prevention mechanism).

So basically, to solve this just copy your private key from the backup in Windows, to WSL, change the permissions there (chmod 600), and work with the WSL copy.

More information on permissionioning Linux private keys.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.