DEV Community

Cover image for Linux on Windows: WSL with Desktop Environment via RDP

Linux on Windows: WSL with Desktop Environment via RDP

Robin Kretzschmar on July 17, 2019

WSL (Windows Subsystem for Linux) is very common these days especially with the new that Windows will ship a Linux kernel with WSL 2.0! Installing...
Collapse
 
liyiliang13 profile image
liyiliang13

Hello, I had no problem login to the Xrdp desktop. However, when I run gedit in terminal, an error pops out:
(gedit:28949): Gtk-WARNING **: 22:46:09.321: cannot open display: 172.28.240.1:0.0

However it is okay if I double click a text file a gedit GUI would run without problem. I have tried export DISPLAY=:0.0 but no luck. Any ideals?

Collapse
 
darksmile92 profile image
Robin Kretzschmar

You need to find out the display which the X server assigned.
Maybe you have luck with:

cat /proc/$pid/environ | tr '\0' '\n' | grep ^DISPLAY=

Can you try that?

Collapse
 
avanishsubbiah profile image
avanishsubbiah

Hello, I followed the instructions for other debian based distros because I am using Ubuntu 18.04 on WSL 2. I am able to get to the Xrdp login in page; however, as soon as I type in my WSL credentials it closes out back to the RDP window.

Collapse
 
rescenic profile image
Muhammad Ridwan Hakim, S.T. • Edited

In Ubuntu WSL:
sudo apt-get purge xrdp

then

sudo apt-get install xrdp
sudo apt-get install xfce4
sudo apt-get install xfce4-goodies

configure :
sudo cp /etc/xrdp/xrdp.ini /etc/xrdp/xrdp.ini.bak
sudo sed -i 's/3389/3390/g' /etc/xrdp/xrdp.ini
sudo sed -i 's/max_bpp=32/#max_bpp=32\nmax_bpp=128/g' /etc/xrdp/xrdp.ini
sudo sed -i 's/xserverbpp=24/#xserverbpp=24\nxserverbpp=128/g' /etc/xrdp/xrdp.ini
echo xfce4-session > ~/.xsession

sudo nano /etc/xrdp/startwm.sh
comment these lines to:
#test -x /etc/X11/Xsession && exec /etc/X11/Xsession
#exec /bin/sh /etc/X11/Xsession

add these lines:
# xfce
startxfce4

sudo /etc/init.d/xrdp start

Now in Windows, use Remote Desktop Connection
localhost:3390
then login with Xorg, fill in your username and password.

Collapse
 
raviln profile image
Ravil Nugmanov

Hi,
First I followed original instructions, but after connecting over RDP and entering login credentials, it was closing the RDP session immediately.
Then I run all commands from Ridwan's post, and now it works well!
Thank you Robin and Ridwan!
PS: I have Ubuntu 20.04 installed in WSL 2.

Thread Thread
 
darksmile92 profile image
Robin Kretzschmar

It seems like newer versions of wsl are having this behavior, good that Ridwan shared his solution and you got it working with it 😊

Thread Thread
 
bagoes profile image
bagoes

I have run Ubuntu with xfce on WSL1 using VcXsrv, but can't use the browser. I tried to update Windows to be able to try WSL2, it turns out that xfce could not run due to display problems. Finally here I found the solution by Ridwan, of courser Robin also who made the tutorial thread, as well as other commentators. Thanks.

Collapse
 
vinimartins profile image
Vinicius Martins

Thaaaanks! It Worked

Collapse
 
mark_cheshire_2c5fea0a285 profile image
Mark Cheshire

I was stuck on this for the longest time. After starting the RDP session I would just be return to the intital RDP screen after entering my credentials. I could not find the startwm.sh file, so I kept looking. All troubleshooting paths kept pointing to this solution. Finally I found the hint hidden in log files. On my Fedora system this file is located at: /usr/libexec/xrdp/startwm.sh. Once I had the right file I could comment out # . /etc/X11/xinit/Xsession and add:
# xfce
startxfce4

Then everything was fine. Thanks so much.

Collapse
 
dowenrei profile image
wenrei

Superb, thanks! Editing the startwm.sh file solves the problem of closing the rdp session after entering the login credentials.
FYI: It only works on Ubuntu 20.04, Ubuntu 18 wouldn't work for me

Collapse
 
myrons profile image
Myron

Thank-you. Worked perfectly. :-)

Collapse
 
r33code profile image
r33

Those instructions did the trick for me. :)
Thank you very much.

Collapse
 
bakaratiq profile image
Mohammad Abubakar Atiq

I just change the port to 3400 i hope it dont effect the server but this error is coming up. Any recommendations?

Thread Thread
 
rescenic profile image
Muhammad Ridwan Hakim, S.T.

which error?

Collapse
 
asap profile image
S.P.

Thanks, @rescenic ! I had the same problem, you solution works

Collapse
 
darksmile92 profile image
Robin Kretzschmar

Can you open a wsl command line end check the logs right after this happens?
I'd check at least those logs:
tail -n 100 /var/log/syslog
tail -n 100 /var/log/xrdp-sesman.log
tail -n 100 var/log/sesman.log

Collapse
 
pyroglyph profile image
Connor McCarroll

I have the same issue.
/var/log/syslog and /var/log/sesman.log don't exist for me, but /var/log/xrdp-sesman.log contains the following:

[20200309-11:24:30] [DEBUG] libscp initialized
[20200309-11:24:30] [DEBUG] Testing if xrdp-sesman can listen on 127.0.0.1 port 3350.
[20200309-11:24:30] [DEBUG] Closed socket 0 (AF_INET6 ::1 port 3350)
[20200309-11:24:30] [INFO ] starting xrdp-sesman with pid 15356
[20200309-11:24:30] [INFO ] listening to port 3350 on 127.0.0.1
[20200309-11:24:54] [INFO ] A connection received from ::1 port 9186
[20200309-11:24:55] [INFO ] ++ created session (access granted): username pyro, ip ::ffff:127.0.0.1:9181 - socket: 11
[20200309-11:24:55] [INFO ] starting Xorg session...
[20200309-11:24:55] [DEBUG] Closed socket 8 (AF_INET6 :: port 5910)
[20200309-11:24:55] [DEBUG] Closed socket 8 (AF_INET6 :: port 6010)
[20200309-11:24:55] [DEBUG] Closed socket 8 (AF_INET6 :: port 6210)
[20200309-11:24:55] [DEBUG] Closed socket 7 (AF_INET6 ::1 port 3350)
[20200309-11:24:55] [INFO ] calling auth_start_session from pid 15381
[20200309-11:24:55] [DEBUG] Closed socket 6 (AF_INET6 ::1 port 3350)
[20200309-11:24:55] [DEBUG] Closed socket 7 (AF_INET6 ::1 port 3350)
[20200309-11:24:55] [INFO ] /usr/lib/xorg/Xorg :10 -auth .Xauthority -config xrdp/xorg.conf -noreset -nolisten tcp -logfile .xorgxrdp.%s.log      [20200309-11:24:55] [CORE ] waiting for window manager (pid 15382) to exit
[20200309-11:24:56] [CORE ] window manager (pid 15382) did exit, cleaning up session
[20200309-11:24:56] [INFO ] calling auth_stop_session and auth_end from pid 15381
[20200309-11:24:56] [DEBUG] cleanup_sockets:
[20200309-11:24:56] [DEBUG] cleanup_sockets: deleting /var/run/xrdp/sockdir/xrdp_chansrv_audio_out_socket_10
[20200309-11:24:56] [DEBUG] cleanup_sockets: deleting /var/run/xrdp/sockdir/xrdp_chansrv_audio_in_socket_10
[20200309-11:24:56] [DEBUG] cleanup_sockets: deleting /var/run/xrdp/sockdir/xrdpapi_10
[20200309-11:24:56] [INFO ] ++ terminated session:  username pyro, display :10.0, session_pid 15381, ip ::ffff:127.0.0.1:9181 - socket: 11

I'm not entirely sure what's going on here. Any ideas?

Thread Thread
 
darksmile92 profile image
Robin Kretzschmar

Sorry no idea just from the logs.
Can you please post the content of your xorg.conf file?
Maybe this gives a hint.

Thread Thread
 
pyroglyph profile image
Connor McCarroll

Sure, here it is:

Section "ServerLayout"
    Identifier "X11 Server"
    Screen "Screen (xrdpdev)"
    InputDevice "xrdpMouse" "CorePointer"
    InputDevice "xrdpKeyboard" "CoreKeyboard"
EndSection

Section "ServerFlags"
    Option "DontVTSwitch" "on"
    Option "AutoAddDevices" "off"
EndSection

Section "Module"
    Load "dbe"
    Load "ddc"
    Load "extmod"
    Load "glx"
    Load "int10"
    Load "record"
    Load "vbe"
    Load "xorgxrdp"
    Load "fb"
EndSection

Section "InputDevice"
    Identifier "xrdpKeyboard"
    Driver "xrdpkeyb"
EndSection

Section "InputDevice"
    Identifier "xrdpMouse"
    Driver "xrdpmouse"
EndSection

Section "Monitor"
    Identifier "Monitor"
    Option "DPMS"
    HorizSync 30-80
    VertRefresh 60-75
    ModeLine "1920x1080" 138.500 1920 1968 2000 2080 1080 1083 1088 1111 +hsync -vsync
    ModeLine "1280x720" 74.25 1280 1720 1760 1980 720 725 730 750 +HSync +VSync
    Modeline "1368x768" 72.25 1368 1416 1448 1528 768 771 781 790 +hsync -vsync
    Modeline "1600x900" 119.00 1600 1696 1864 2128 900 901 904 932 -hsync +vsync
EndSection

Section "Device"
    Identifier "Video Card (xrdpdev)"
    Driver "xrdpdev"
EndSection

Section "Screen"
    Identifier "Screen (xrdpdev)"
    Device "Video Card (xrdpdev)"
    Monitor "Monitor"
    DefaultDepth 24
    SubSection "Display"
        Depth 24
        Modes "640x480" "800x600" "1024x768" "1280x720" "1280x1024" "1600x900" "1920x1080"
    EndSubSection
EndSection
Collapse
 
darksmile92 profile image
Robin Kretzschmar

You could start analyzing it by checking the logs. Open your wsdl env in powershell and check logs located at /var/log for clues.

Collapse
 
elvisvan profile image
Elvis Van

update on 8/2022, there's a new kali-specific package for this called kali-win-kex, it's been pretty smooth and a lot more easy to setup than this

Collapse
 
darksmile92 profile image
Robin Kretzschmar

Thanks! I updated the post referencing your comment.

Collapse
 
vaniccia profile image
Winson Chao

I have the same issue that the RDP window is closed as soon as I type in my credentials in Xrdp login page. It's already resolved by:

echo xfce4-session > ~/.xsession

Collapse
 
camerongoodman profile image
Cameron

This worked

Collapse
 
linuksfan profile image
linuksfan • Edited

Hi, I tried the tutorial, posts by M. Ridwan Hakim, Winson Chao.
I'm noob. I have Windows 10 Home and Debian on WSL.
Can you help ??

After entering the username and password, a window pops up:

Connection Log

connecting to sesman ip 127.0.0.1 port 3350
sesman connect ok
sending login info to session manager, please wait...
login failed for display 0

Collapse
 
darksmile92 profile image
Robin Kretzschmar

I found this issue related to Kali Linux on WSL and since Kali is based on Debian, please check the issue with the comments and try the solution that worked out in their case.

They changed the Xorg backend to Xvnc to solve this.

Collapse
 
soatesuk profile image
Simon Oates

This error is because Windows 10 home edition doesn't all RDP. I'm going to wait until the MS GUI release which should be in March 2021

Collapse
 
noneofyourbusiness1415252 profile image
Umar

No it doesn't make a difference whether you're on Home or Professional; you can still connect to RDP, even on Android. The xrdp server is running on WSL, not the main Windows, so it isn't affected. I have Kubuntu Desktop running perfectly on Windows 10 Home Edition. For me, that message comes up when I put in the wrong password.

Thread Thread
 
noneofyourbusiness1415252 profile image
Umar

Proof:

Collapse
 
linuksfan profile image
linuksfan

How to insert a picture ??

Collapse
 
rescenic profile image
Muhammad Ridwan Hakim, S.T.

login failed means, you can't login to xorg session, try reset your account password in ubuntu wsl.
passwd username or sudo passwd username.

Collapse
 
neuquenfr profile image
neuquenfr

Hi. I'm absolutely new in this and followed your instructions step by step.
The last line of the process shows:

  • Starting Remote Protocol server [OK]

However, trying to access my Localhost:3390 (or through my local IP address) returns an ERR_CONNECTION_REFUSED error on Chrome ver. 84.0.4147.105
or
on Firefox ver. 79.0, a blank page with some special characters on it.
(Win 10 PRO / 2004)

Could you please help me?

Many thanks in advance! (sorry if this comment is displayed twice)

Collapse
 
darksmile92 profile image
Robin Kretzschmar

Hey neuquenfr, the port 3390 is the port for RDP (Remote Desktop Protocol) connection so you should use remote desktop to connect to your desktop environment within the WSL.

You can't use a Browser for that.

One way would be to search for mstsc in Cortana or the start menu and connect with this.

Collapse
 
neuquenfr profile image
neuquenfr

Thank you so much, Robin, for your prompt response.

It works, now.

Great help!

Collapse
 
morgs88 profile image
Brett Morgan

Awesome article, thanks! Helped clarify a few things after dismissing WSL2 a while back, updates dont seem to work as well if I'm connected through my VPN service, any idea why that is? It doesn't get all the repo packages but after i disconnect from the VPN it upgrades fine, kind of weird!

Collapse
 
darksmile92 profile image
Robin Kretzschmar

This sounds strange. My first guess would be your VPN provider blocks some of the needed DNS records from resolving or anything else that changes during your VPN connection.

Collapse
 
graziamk profile image
graziamk

I just really wanted to thank you. Your post was tremendously helpful because it solved a WSL problem that I've been working on for two days. I was getting very strange errors from xfce4 and xrdp (no DISPLAY, no console, etc.), and read through hours' worth of posts, and nothing solved my problem. I reinstalled WSL2 about 7 times, with different attempts, the problem remained. The changes to the xrdp.ini script that you mentioned both solved the issue AND allows me to use localhost to RDP into WSL2 (I certainly was tired of changing the RDP IP almost daily). Can't get better than that. I owe you cofee!!

Collapse
 
darksmile92 profile image
Robin Kretzschmar • Edited

I'm really happy to read that my article was able to help you solve the problem, I know the feeling of being stuck with such things and searching for days too well :)

Buy me a coffeeBuy me a coffee

Collapse
 
mattdmo profile image
Matt Morrison

Is there a way to modify this procedure to use GNOME instead of xfce? I've tried putting gnome-session in ~/.xsession instead of startxfce4, as well as anything else I can think of, but it's not working.

Collapse
 
hussainisaiduabubakar profile image
hussainisaiduabubakar

I have followed all the above instruction and it works till when I log in my credentials then after that it output 'unable to contact settings server, failed to execute child process "dbus-launch" (no such file or directory)' pls I need it been trying to fix it for months now,
thank u

Collapse
 
darksmile92 profile image
Robin Kretzschmar

This reddit thread seems to have a solution that worked for a couple of people, maybe try it with this:

sudo apt-get install dbus-x11
Enter fullscreen mode Exit fullscreen mode
Collapse
 
leftykreouzis profile image
lefty-kreouzis

I installed configured xrdp and xfce4
I started xrdp and can connect using remote desktop
I can log in but the session is not starting - just a blank green background and eventually an error message

Connectiong to sessman ip 127.0.0.1 port 3350
sessman connect ok
sending login info to session manager, please wait...
started connecting
connection problem, giving up
some problem

Collapse
 
hussainisaiduabubakar profile image
hussainisaiduabubakar

hello, pls I followed the procedure u gave up but when I log in to RDP after putting in my credentials then it will go blank and output a message, 'unable to connect settings server. failed to execute child process"dbus-launch" (no such file or directory)'

Collapse
 
hussainisaiduabubakar profile image
hussainisaiduabubakar • Edited

pls i have followed all the procedure but after assigning my credentials is now showing 'unable to connect settings server, failed to execute child process "dbus-launch" (no such file or directory)' can anyone help me solve this issue.
thank u

Collapse
 
hussainisaiduabubakar profile image
hussainisaiduabubakar

I have followed all the above instruction and it works till when I log in my credentials then after that it output 'unable to contact settings server, failed to execute child process "dbus-launch" (no such file or directory)' pls i need it been trying to fix it for months now,
thank u

Collapse
 
jkalberto profile image
jkalberto

Thanks for this article. I have been wanted to do this, but did not know how.
Followed your instructions and everything seems to be working.

Collapse
 
mmadhanmohanna2 profile image
M.Madhan Mohan Naidu

Hello
I successfully login to my Linux account once and I logout from that account and if I try to login again by using my user ID and passwd then i am getting this

connection to the sesman ip 127.0.0.1 port 3350
sesman connect ok
sending login info to session manager, please wait....
login failed for display 0

I got this when i trying to login. So please help me solve that problem and help me to login

Collapse
 
darksmile92 profile image
Robin Kretzschmar • Edited

Do you have a session greeter runnning? Which linux distro are you running inside the WSDL?
And maybe your display is not :0 but :1.

Collapse
 
cefeboru profile image
Cesar Fernando Bonilla

How could we start xrdp automatically? Or it already does it with the steps in the guide?

Collapse
 
darksmile92 profile image
Robin Kretzschmar

Hey Cesar, to start the xrdp service automatically, you can enable the systemd service with the following lines:

sudo systemctl enable xrdp
sudo systemctl start xrdp
Collapse
 
myrons profile image
Myron • Edited

What have I done wrong? Using latest LTS distro under WSL2.

sudo systemctl start xrdp
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down

Collapse
 
neuquenfr profile image
neuquenfr • Edited

Hi. I'm absolutely new in this and followed your instructions step by step.
The last line of the process shows:

  • Starting Remote Protocol server [OK]

However, trying to access my Localhost:3390 (or through my local IP address) returns an ERR_CONNECTION_REFUSED error on Chrome ver. 84.0.4147.105
or
on Firefox ver. 79.0, a blank page with some special characters on it.
(Win 10 PRO / 2004)

Could you please help me?

Many thanks in advance!

Collapse
 
gilsomoura profile image
Gilson de Moura

Its only works for Windows 10 Pro?

Collapse
 
darksmile92 profile image
Robin Kretzschmar

The WSL feature is available on all Windows 10 versions that meet the requirements specified in the MSDN Docs here and here.

Those are:

  • Ensure that WSL feature is enabled (it's an optional feature). Open a PowerShell as admin and run the following:
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
  • Windows 10 build 18917 or higher
  • Download a distro from the Windows Store (see docs)
Collapse
 
negue profile image
negue

Is there a way to xrdp into ubuntu-desktop? I installed xrpd, try'd everything mentioned here, but when I login , RDP just closes - no errors in xrdp-sesman.log

Collapse
 
darksmile92 profile image
Robin Kretzschmar

Thats a good question. I can't think of a clear path on how to debug this, but maybe it is worth checking /var/log directory, list the files with ls -t to have the most recent modified ones at the top and check those right after the xrdp connection closed.

Hopefull this would give you a hint.

Feel free to post the logs here and I try to help analyze them.

Collapse
 
emcclure profile image
emcclure • Edited

I followed the instructions and it work. the only error so far was: sleep: cannot read realtime clock: Invalid argument. this was when I tried to start the rdp.

Collapse
 
dantedpoe profile image
Dante Poe

If I wanted to do this with qtile, how would I change it? Thanks so much!

Collapse
 
darksmile92 profile image
Robin Kretzschmar

Sorry I have no experience with qtile. Can you check if there is a display specified in the config of qtile?

Collapse
 
chriswiley profile image
Chris Wiley

Can this also just run GUI applications without starting the desktop? Sometimes I just need a certain app running and not the whole environment. Or would it be best just to use XServer?

Collapse
 
darksmile92 profile image
Robin Kretzschmar • Edited

You can skip the RDP part and start your GUI from the WSL command prompt right away. Just export your Display and run the program.
Not tested, but something like this: DISPLAY=:0 chromium &
XServer is always a good idea :)

You can get inspiration from my other post using docker to run GUI:

Collapse
 
mashruf profile image
Shafiul islam mashruf

well everything is fine except whenever I connect RDP it opens WINDOWS
any solution?

Collapse
 
bakaratiq profile image
Mohammad Abubakar Atiq

i just change the port from 3390 to 3400 and it still dont work.