我的 Windows Bash shell 在与 Windows 文件系统交互时运行的是哪个用户?

ubi*_*bie 5 bash windows-subsystem-for-linux

我已经下载并安装了 Windows 版 Bash。当我做一个 simple 时ls -al,我得到了很多权限被拒绝的错误。

我不太清楚用户权限是如何解决的。假设在 bash shell 中,我设置了一个名为moihome drive的用户/home/moi。如果我这样做ls -al /mnt/c,我会收到一堆权限被拒绝的错误,例如

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
Run Code Online (Sandbox Code Playgroud)

我已经检查了“Windows 端”并且没有名为moi. 因此,例如,当ls报告权限被拒绝时/mnt/c/swapfile.sys,哪些用户被拒绝?

一个后续问题是:我需要做什么才能获得 Bash 用户并将其称为我的“普通”Windows 用户以拥有相同的权限?

Tim*_*Tim 2

Windows 用户是启动bash.exe. 您可以通过在 Linux/mnt/c目录中创建一个文件并查看 Windows 中该文件的所有者来验证这一点。

从 Windows 命令提示符处:

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
Run Code Online (Sandbox Code Playgroud)

请注意,它bash.exe是由tim用户启动的,并且C:\test\foo.txt从 WSL 创建的文件也归tim.