XRDP (in a WSL distro) not connecting to remote desktop
Solution 1:
For xrdp
specifically, try:
wsl ~ -u root -e sh -c "nohup service xrdp start"
While a wsl -u root -e sh -c "command"
will work for most commands (and even most services), the init.d
script for xrdp
seems to have an issue with this. I believe this is due to a timing issue, where the shell (the owning process) terminates before xrdp
gets a chance to fork. nohup
just makes sure that the full xrdp
init script gets a chance to run before that happens.
This really isn't a WSL issue -- The same thing can be seen if you were do something similar with exec sh -c "sudo service xrdp start"
.
Solution 2:
Note: This answers the question as originally asked -- How to pass input to the WSL command. However, the question was subsequently edited to add this answer to the question and raise a new issue. Leaving it here for historical purposes.
Try something along the lines of:
wsl --user root --distribution kali-linux --exec sh -c "service xrdp start" # long form options
wsl -u root -d kali-linux -e sh -c "service xrdp start" # short form
That should work. It runs the distro as root (to avoid the use of a password on sudo
), and execs the sh
(for fastest execution time and avoidance of any of your normal shell's startup scripts) with a commandline of service xrdp start
.
You might also consider:
wsl -u root -d kali-linux -e sh -c "service xrdp status || service xrdp start"
Which will first check to see if it's running before starting it.
Alternative invocation from CMD:
echo service xrdp start | wsl -u root -d kali-linux -e sh
But quoting rules start to get much more hairy, IMHO.