wsl-sudo
wsl-sudo copied to clipboard
`socket.timeout: timed out` when running under sudo or otherwise as root?
Is there any way I can use both wsl-sudo.pl
and sudo
at the same time without having to enter my linux password every time?
As I pointed out in #1, wsl-sudo works fine to edit e.g. the hosts file under WSL2, but I also need my script to have linux sudo priviledges.
If I run
wsl-sudo.py sudo ls -l
sudo asks for a password every time, presumably because wsl-sudo.py creates a new pty for each invocation.
But if I run this (where I preserve the PATH
so it can find wsl-sudo.py and misc. windows binaries):
sudo env "PATH=$PATH" wsl-sudo.py ls
I'm presented with the UAC prompt but then get this, which I'd like to avoid:
Traceback (most recent call last):
File "/home/peter/bin/local/wsl-sudo/wsl-sudo.py", line 332, in <module>
main()
File "/home/peter/bin/local/wsl-sudo/wsl-sudo.py", line 328, in main
UnprivilegedClient().main(**vars(args))
File "/home/peter/bin/local/wsl-sudo/wsl-sudo.py", line 233, in main
self.sock, acc = listen_socket.accept()
File "/usr/lib/python3.8/socket.py", line 292, in accept
fd, addr = self._accept()
socket.timeout: timed out
This occurs both if I run as above, if I run sudo -i
to get an interactive shell, or run wsl -u root
to start a brand new WSL session.
I assume you applied #2 to get wsl-sudo working on wsl2? Then I would guess that your problem with sudo env "PATH=$PATH" wsl-sudo.py ls
is that sudo
removes the WSL_INTEROP
variable, undoing the effect of #2. You could try sudo -E wsl-sudo.py ls
instead. Which is probably what you want anyways.
You could also just permanently disable the password prompt for sudo: https://askubuntu.com/a/147265. I think that is in general a sensible thing to do on WSL. Then you can do wsl-sudo.py sudo ls -l
.
Thanks for replying.
I'm not sure I'm crazy about disabling sudo password prompting. But yes, that is a solution.
I don't understand the first part of your reply, though:
The socket.timeout: timed out
occurs with or without #2 applied.
I would guess that your problem with sudo env "PATH=$PATH" wsl-sudo.py ls is that sudo removes the WSL_INTEROP variable
But:
-
sudo
runs beforewsl-sudo.py
so how can it possibly remove theWSL_INTEROP
that hasn't been set yet? - It also occurs with
wsl.exe -u root
starting directly as root - completely without sudo - as in:
WSL2@~» wsl.exe -u root
root@COMPANY-12D2Z0:/home/peter# /home/peter/bin/local/wsl-sudo/wsl-sudo.py ls
Traceback (most recent call last):
File "/home/peter/bin/local/wsl-sudo/wsl-sudo.py", line 333, in <module>
main()
File "/home/peter/bin/local/wsl-sudo/wsl-sudo.py", line 329, in main
UnprivilegedClient().main(**vars(args))
File "/home/peter/bin/local/wsl-sudo/wsl-sudo.py", line 234, in main
self.sock, acc = listen_socket.accept()
File "/usr/lib/python3.8/socket.py", line 292, in accept
fd, addr = self._accept()
socket.timeout: timed out
root@COMPANY-12D2Z0:/home/peter#
#2 does not invent the WSL_INTEROP variable. The call graph of wsl-sudo is: linux wsl-sudo
→ windows powershell
→ windows wsl.exe
→ linux wsl-sudo
(see readme). #2 forwards the WSL_INTEROP variable in the first call from linux to windows. Have a look at your wsl2 env: the WSL_INTEROP
variable should already be set.
You can have a look at these issues to get more understanding of the situation: https://github.com/microsoft/WSL/issues/4465 and https://github.com/microsoft/WSL/issues/5065. It's possible that you are encountering the latter issue here, when you run wsl.exe from within a wsl prompt. I can't really help you there – these are all undocumented WSL2 internals.