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

时间:2016-09-27 08:03:15

标签: bash windows-subsystem-for-linux

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

我不清楚如何解析用户权限。让我们说在bash shell中我设置了一个名为moi的用户并拥有主驱动器/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

我已经检查了" Windows端"并且没有名为moi的新用户。那么,当ls报告/mnt/c/swapfile.sys的权限被拒绝时,会拒绝哪些用户?

接下来的问题是:我需要做些什么才能让Bash用户称之为"正常" Windows用户拥有相同的权限?

2 个答案:

答案 0 :(得分:2)

Windows用户是启动bash.exe的用户。您可以通过在/mnt/c目录中从Linux创建一个文件来查看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

请注意bash.exe用户已启动tim,而从{WSL}创建的C:\test\foo.txt文件也归tim所有。

答案 1 :(得分:0)

您可以使用Windows文件资源管理器访问Linux文件系统。它位于AppData \ Local文件夹中。它是半隐藏的"但可以访问:

C:\用户\ [用户名] \应用程序数据\本地\ lxss \根文件系统