-
Notifications
You must be signed in to change notification settings - Fork 823
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bash $PATH includes native Windows path entries #1640
Comments
@markgross people asked in UserVoice to be able to run Windows commands from bash, so it should be a feature. As it is appended to the PATH, it shouldn't make any difference if you have python or any other linux programs installed on WSL. If you don't want that to happen, just export PATH containing only WSL folders on ~/.bashrc . :) |
@Gabrielcarvfer: It makes a difference if you have installed a tool in Windows but not in linux. Usually you'd get an error like "tool XY is currently not installed. Type sudo apt install ... to install it now". If the windows version gets picked up instead, everything works either as expected or you might get very strange errors. |
Default options should be secure options. If someone wants to add power shell env path's to their bash env they can so. But, adding things by default is IMO a problem that will bite people in the future. Also, I don't want any python scripts or executable leaking between my windows and linux environments. |
@MikeGitb and @markgross , a switch for that in Settings's Developer section for that (injecting Windows path on WSL path) would solve your problem, but this is a work in progress, in a prerelease build, then you can use the workaround until they fix it. |
@markgross -- to answer your implied initial question, this is a deliberate feature. Regarding your concern about namespace collisions -- note that Windows executables must have a file extension such as Regarding security -- my expectation right now as a user is that any malicious WSL process can acquire Linux root at any time. If you've already got root, messing with stuff in $PATH is small potatoes :-) WSL processes (even ones running as root) are all just unprivileged (as far as Windows is concerned) programs running under your Windows user account. So the environment is effectively single-user, and should IMO be secured accordingly. (The WSL team is probably looking into more-sophisticated security models, but that's what exists today, as far as I can tell.) Regarding controlling this behavior, take a look at #1493 . |
On my system the bash path is truncated for some reason I can't figure: Where the original Windows path ends with Also for some reason the .profile is not adding my ~/bin directory to the path, I have copied the relevant code to the end of .bashrc and it works fine so not sure what is going on there |
I agree with @aseering. Since you have also provide the file extension to invoke the Windows binaries I think it is pretty unlikely that there will be much confusion. @markgross if you have a specific case where this is happening kindly reopen this ticket. You can disable this feature by setting this registry key:
@itomkins - I assume you're running an older insider build? There was an off by one error that is fixed in recent builds. |
@aseering - yes it is. |
Thanks @benhillis @aseering correct on both points, added --login to shortcut and will have to switch from slow to fast to pick up a newer build i guess. |
I just watched some videos from https://blogs.msdn.microsoft.com/commandline/learn-about-bash-on-windows-subsystem-for-linux/ Specifically https://sec.ch9.ms/ch9/ed3c/e3560e79-4719-49dc-a7e8-607ca516ed3c/WindowSubsystemforLinuxFileSystem_high.mp4 around time stamp 22min it talks about the effects of native windows programs operating on WSL files. It results in files that can't be seen from the bash environment. Please explain why allowing windows path's is a good idea? It looks like a train wreck given this new information. |
Hmm, I guess there is one more video I needed to watch before posting my last comment. Still, if I do the following I get a bad experiance:
I can't edit the content I added and I can't save anychanges I made over top temp.txt |
Hi @markgross -- have you actually tried running the command that you suggest? I think you will find that the set of things that you can't do is larger than you are saying :-) |
@markgross - Due to the filesystem limitations you mention above accessing files in LxFs (anything not under /mnt/*) is not supported via interop. You won't be able to modify files in LxFs unless you do some trickery like passing the full NT path of .bashrc to gvim.exe. I'd suggest trying out the feature and seeing how it works. I'd love to hear specific feedback about things that aren't working as you expect. As long as you're working out of one of your mounted NTFS drives you shouldn't run into issues. As an aside: the limitation of not being able to modify files in LxFs is something we're spending a lot of time looking at for a future release. I would love to come up with a solution that gets rid of this limitation - but creating a mapping between Linux and NT security models is a complicated problem. Just ask anybody who's worked on samba :) |
Thanks. I will think some more about the VSF/NTFS issues for content not under /mnt/[a..z]. FWIW I have not done any powershell based development so a lot of the utility for this feature is lost on me. but, I do work in linux on native Linux boxes. Yes, those mappings are not simple to deal with. they are so complex I would punt on it. Understanding the use case after watching your interview helps. I'm still not sure its worth the native linux file inconsistencies that happen because of having this feature. ok, I don't think its worth it because of the LxFs / NTFS extended attributes (and caching) issues. but, I agree its handy when operating on NTFS files under /mnt/[a..z] somewhere and wanting to use native linux user mode tools. FWIW I'd hide the extended path from the normally launched bash shell but enable it from powershell command line invocations of base.exe if I couldn't address the LxFs / NTFS issues enough for a good UX. But, the user needs to be aware of the file system limitations. Thanks for the responses! I've been very impressed with the direct interaction with you developers on WLS. |
Not sure where the idea that "since you have to also provide the file extension to invoke the Windows binaries I think it is pretty unlikely that there will be much confusion" is coming from. Perhaps this helps illustrate the problem: Me on any other Ubuntu system:
It's a super-helpful feature and incredibly streamlined workflow. I don't even worry about whether some CLI snippet I see online needs a tool I don't have. I just paste it and if something is missing, Bash tells me exactly how to get it. Me using Ubuntu bash on Windows:
Incredibly unhelpful, and not a very good experience for those who are used to Linux and expect the WSL environment to be more "clean". I didn't type any Windows extension anywhere for this to happen. I think the intersection of people who have Very glad to see the regedit entry to solve this, but exposing it more visibly would be quite welcome. At any rate, thanks for listening, I'm very much enjoying WSL so far... |
Here's another workaround, although not the most elegant one. If you add this to the end of your .bashrc file, all references to Windows PATHs will be removed. In my case 20 elements are removed and only 8 are left:
Not sure if this will catch everything, but it does the trick for me. |
FWIW I just changed my PATH to be what it should be in the bashrc file.
similar to what you have just without the perl magic.
…On Sun, Oct 8, 2017 at 1:04 PM, oterhals ***@***.***> wrote:
Here's another workaround, although not the most elegant one.
If you add this to the end of your .bashrc file, all references to Windows
PATHs will be removed. In my case 20 elements are removed and only 8 are
left:
PATH=$(/usr/bin/printenv PATH | /usr/bin/perl -ne 'print join(":", grep {
!/\/mnt\/[a-z]/ } split(/:/));')
Not sure if this will catch everything, but it does the trick for me.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1640 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AADz5OnC7OybBxRWkwq8-afI4cfHFmJQks5sqSq5gaJpZM4LwlT1>
.
--
create interesting things.
|
I write a script to resolve it, append #!/bin/bash
IFS=':'
NEWPATH=''
for p in ${PATH[@]}
do
if [ "${p:0:5}" != "/mnt/" ]; then
NEWPATH+=":$p"
fi
done
IFS=' '
export PATH=${NEWPATH:1} |
The rationale for closing this bug is that "you need to include the file extension in order to invoke windows executables". But as @irontoby demonstrated (I see the same behavior on my system), this just isn't true. If you invoke Even with I don't believe that this bug should be closed. |
@mpiroc - That's because the node guys removed the .exe extension from their binary. |
@benhillis On my machine, it's still present:
|
@mpiroc - Look in that directory, you'll also find a "node" file with no extension. |
|
Correct, but I want Windows to automatically prepend 'wsl' based on any commands it finds in my path that are in linux via WSL. This will let things like extensions in vs code call out to 'npm' and have it run the linux version. |
That's #1823 |
EDIT 2019-05-17 @m00head 's comment next to mine is the best workaround since it doesn't involve hacking anything in your bash profile: #1493 (comment) regedit here:
Change Now my path looks like this:
|
I have posted the latest workaround for this issue here: #1493 (comment) |
this is a horrible call of judgement and I am apalled this has not been fixed yet. this should not be on by default. It should be other way around. |
As the windows paths are added to the tail of PATH, it have preference. |
A note to those that have stumbled upon this thread via searching: forget the registry tweaks mentioned here and elsewhere, as they keep changing. I used the method mentioned in #1493 and it worked like a charm:
I'm sure @mchiasson's solution, @oterhals solution, etc. work as well; the benefit of any of these methods is that since the changes are within the WSL environment itself, the fix will survive whatever Microsoft decides to "tweak" later on. And for the record, add me to the list of people who are baffled that this "feature" is enabled by default. It's not a lot of fun trying to diagnose errors such as |
@DavidKDeutsch Thank you so much. You are a life saver |
@m00head 's workaround is the best one so far : #1493 (comment) |
Fix at #1493 fixes this flutter error for anyone landing here from google.
|
Instead of trying to fiddle with the path or the registry, just disable the feature. in WSL: sudo vi /etc/wsl.conf add: [interop]
appendWindowsPath = false then in Windows find your distro name and terminate it so the config changes are picked up: wsl.exe --list
wsl.exe --terminate <distro_name> |
That option was added long after this issue was closed, and is mentioned in #1493 , but still helpful to document it here as well I guess. |
The approach to edit
solved this problem for me. I no longer have Windows executables on my path. But it changed how I have to start VS Code with WSL now. Just thought I'd mention it in case someone else googles it and ends up here. I used to be able to start VS Code for Remote WSL work by typing So now, since VS Code can't be started from within WSL, start open VS Code in Windows (with the remote extension installed) and use the command palette (because the option doesn't show up in the GUI) menu to select Then, |
@mattwelke To solve that problem you can include the Windows installation of vs code in your path explicitly, e.g. echo PATH=\$PATH:/mnt/c/Users/`whoami`/AppData/Local/Programs/Microsoft\\ VS\\ Code/bin >> ~/.bash_profile |
Quoted rather than escaped is probably more straightforward, and that leading backslash doesn't look right, and your WSL username is not necessarily your Windows username. This said, cherry picking Windows paths in |
Would this be an effective way to limit access to Windows executables to just VS Code (or some other program) while keeping Windows binary interop turned on? For example, to prevent |
That's true that the username doesn't have to match, good call. As for the leading backslash, thats because it would expand your current path if you didn't do that. |
My ~/.bashrc does not contain Windows PATH. WSL2 Ubuntu |
Also adding this keys windows path remain [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Lxss] "AppendNtPath"=dword:00000000 Also Here |
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Lxss{GUID}\Flags I've lost everything. And Windows path remain. |
Solved overwriting the path ~/.profile |
I just noticed that there are entries in the bash PATH that include windows executibles. I'm not sure if this is a feature or a bug.
I see that my Anaconda3 (a windows python distrobution) has executibles on the bash path. I expected only linux native programs to be accessible from the ubuntu bash env.
mgross@marks-x1:
$ which fetch_file.exe$ echo $PATH/mnt/c/Program Files/Anaconda3/Scripts/fetch_file.exe
mgross@marks-x1:
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/mnt/c/Windows/System32:/mnt/c/Windows:/mnt/c/Windows/System32/wbem:/mnt/c/Windows/System32/WindowsPowerShell/v1.0:/mnt/c/Program Files/Anaconda3:/mnt/c/Program Files/Anaconda3/Scripts:/mnt/c/Program Files/Anaconda3/Library/bin:/mnt/c/Users/mark9/AppData/Local/Microsoft/WindowsApp
I worry that the leakage of the Windows environment into the bash will result in unexpected behaviors from time to time.
Your Windows build number
14986.rs_prerelease.161202-1928
Steps / All commands required to reproduce the error from a brand new installation
not sure if Anaconda3 needs to be installed before enabling the WSL or after (or if that matters.)
The text was updated successfully, but these errors were encountered: