Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What user is my Windows Bash shell running as when it interacts with Windows file system?

I have downloaded and installed Bash for Windows. When I do a simple ls -al, I get lots of permission denied errors.

I'm not clear quite how the user permissions are being resolved. Let's say that in the bash shell I set up a user called moi and has home drive /home/moi. If I then do ls -al /mnt/c, I get a bunch of permission denied errors, e.g.

ls: cannot access /mnt/c/hiberfil.sys: Permission denied 
ls: cannot access /mnt/c/pagefile.sys: Permission denied 
ls: cannot access /mnt/c/swapfile.sys: Permission denied total 2388

    drwxrwxrwx 2 root root      0 Sep 26 18:09 .
    drwxr-xr-x 2 root root      0 Jan  1  1970 ..
    drwxrwxrwx 2 root root      0 Oct 22  2015 AutoDiscover
    -r-xr-xr-x 1 root root 398156 Jul 26  2012 bootmgr
    -r-xr-xr-x 1 root root      1 Oct 30  2015 BOOTNXT

I have checked on the "Windows side" and there is no new user called moi. So, when ls reports permission denied for /mnt/c/swapfile.sys for example, what user is being denied?

A follow on question would be: what do I need to do to get the Bash user and call it my "normal" windows user to have the same permissions?

like image 507
ubienewbie Avatar asked Oct 30 '22 19:10

ubienewbie


1 Answers

The Windows user is the user who started bash.exe. You can verify this by creating a file from Linux in the /mnt/c directory looking at the owner of the file in Windows.

From the windows command prompt:

C:\test>echo %USERNAME%
tim

C:\test>bash.exe
wsluser@computer:/mnt/c/test$ touch foo.txt
wsluser@computer:/mnt/c/test$ exit
exit

C:\test>dir /q C:\test\foo.txt
 Volume in drive C is OS
 Volume Serial Number is B8BA-E032

 Directory of C:\test

2017-06-26  02:06 PM                 0 tim   foo.txt
               1 File(s)              0 bytes
               0 Dir(s)  363,224,875,008 bytes free

Notice that bash.exe was started by the tim user, and the C:\test\foo.txt file which was created from WSL is also owned by tim.

like image 68
Tim Avatar answered Nov 15 '22 14:11

Tim