Partilhar via


How to enable Desktop Experience and enable RDP for a CentOs 7 VM on Microsoft Azure

[bing_translator]Normally when you provision a Linux VM on Microsoft Azure, it's provisioned for you on the CLI mode which most of the Linux fans are fund of it but in case you would like to use the desktop experience and RDP to the machine instead of SSH to it, you will need to follow these simple steps.

Connect to the VM using the SSH command tool like Putty.exe

In the upper putty window you can see that I'm connecting to this "VM centosrdp.cloudapp.net" on port 22 which is the default port of ssh, you will need to replace the value of the Host Name and Port with your own, to get this on Microsoft Azure , you will need to navigate to your machine's dashboard on the management portal on Azure, check the screenshot below and obtain the DNS name highlighted below.

After Connecting to the VM on the CLI, you will get prompted to enter your username and password, so go ahead and enter the same username and password you created to access your VM on Azure.

and then run this command to gain root privileges.

 # sudo -s

Install EPEL and nux Desktop repository rpms.

 # rpm -Uvh https://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-1.el7.nux.noarch.rpm

after this is successful, continue by installing the GNOME desktop to get the graphical user interface you desire

 # yum groupinstall "GNOME Desktop" "Graphical Administration Tools"

the installation process will take sometime depending on your internet speed, after the installation is done, run the following command to change the reboot from CLI to GUI.

 # ln -sf /lib/systemd/system/runlevel5.target /etc/systemd/system/default.target

the next step is to install the xrdp to be able to RDP on the VM

 # yum -y install xrdp tigervnc-server

then start the xrdp service

 # systemctl start xrdp.service

then test the xrdp service by running the following command, you should see the next screenshot

 # netstat -antup | grep xrdp

now you can enable the xrdp service

 # systemctl enable xrdp.service

And then add a port in the machine firewall if it was activated, if not then there is no need for the next two commands.

 # firewall-cmd --permanent --zone=public --add-port=3389/tcp
# firewall-cmd --reload

Now that we have configured the CentOs 7 VM to have GUI and we have enabled the xrdp service on it, we have only one step left which is only adding an endpoint to the machine on Azure management portal. Go back to the Azure management portal and go to your VM ENDPOINTS Tab, check the screenshot below and then Add a new endpoint by clicking the Addbutton in the task bar on the lower end of the portal.

After clicking on the Add button, you will have the following form where you select from it RDP and choose keep the default values of the port and then click Ok , this will create a RDP endpoint where you can connect successfully to the machine, after the creation is done, you will see a new record added under your ENDPOINTS This is the view after the creation of the endpoint is succeeded

Now you can test the connection to your VM by clicking on connect button in the VM's dashboard task bar

which will download the RDP file to connect to this VM, click connect on it and then you will see this notification which you will have to click Ok

then the RDP window will open with the following screenshot

Enter your credentials here and then you will see the following prompt windows and viola you did it :)

Comments

  • Anonymous
    June 14, 2015
    Hi k.moussa, I followed the exact steps and login to rdp, but i get a screen with a sad pc image saying:

Oh no! Something has gone wrong. A problem has occurred and the system can't recover. Please log out and try again.


What is missing here?

  • Anonymous
    July 11, 2015
    I was able to follow the exact instructions above and reproduce Karishma's error "Oh no! Something has gone wrong..." I was able to get to the desktop after troubleshooting. I had a number of suspect causes, but I believe the fix was one (or both) of the following:
  1. sudo yum update
  2. sudo adduser <username> sudo passwd <username> (assign password for newly created user) ...I connected to my host via (x)RDP with the new user creds I had created. The desktop session connection was successful. (Note: I have not used the desktop extensively yet.)
  • Anonymous
    July 19, 2015
    hi , I followed the steps . all the steps worked except this one : netstat -antup | grep xrdp . I did not get any statements which you mentioned in the image . Secondly I am able to use Remote desktop for connecting the VM . Its showing the same error message. Can you suggest something ? Thanks Gaurav

  • Anonymous
    July 26, 2015
    I had same problem with Gaurav.I checked the status about xrdp by : systemcrl | grep xrdp, the status was faild. I used followed command. chcon -t bin_t /usr/sbin/xrdp chcon -t bin_t /usr/sbin/xrdp-sesman and restart xrdp. systemctl restart xrdp.service Then I suceeded to connecting the VM.

  • Anonymous
    August 07, 2015
    Outstanding article!   Got me up and running in less that 15 minutes.  Thank you kmossa

  • Anonymous
    October 02, 2015
    Absolutely fantastic article! Begs the question: Why did i have to search Google to find this great msdn article after spending over half an hour poking around in the azure linux VM tutorials.

  • Anonymous
    February 26, 2016
    I am able to connect the VM via RDP. But after I entered the username/pwd while creating the VM...I was prompted to enter password for the user "Administrator" (to create color managed device). What is the default password ? I never set any username "Administrator while creating.

  • Anonymous
    March 13, 2016
    I'm trying to do this for a non-classic vm (resource manager). I installed xrdp and created an inbound rule for port 3389, but when I try to rdp it fails. Id there something I'm missing? Thanks.

    • Anonymous
      April 20, 2016
      For resource manager VMs you can create an inbound rule for RDP in the Network Security Group.
    • Anonymous
      May 24, 2016
      Hi Andrew, sorry for replying that late - was on a long business trip, are you able to reach the machine on the public IP or it rejects the connection?
  • Anonymous
    July 13, 2016
    Thank you k.moussa.

  • Anonymous
    September 19, 2016
    Hello,I follow this steps and it works

  • Anonymous
    September 22, 2016
    I flowed the same link but I am getting blank screen only after login.

    • Anonymous
      September 23, 2016
      Hi Muralidas,Just to make sure I got your point, you followed all the steps in the article and you are able to RDP to your linux VM and after you login with your credentials,it gives you a blank screen ? is this what happens ?
  • Anonymous
    December 29, 2016
    many thanks for this, mine is working.I would like to ask on how secure the xrdp session is.I read here http://xrdp.sourceforge.net/documents/security/ we should create a rsakeys.ini , would you know if this is still necessary or maybe assist on how to do it

  • Anonymous
    January 24, 2017
    Hi Guys,How to we set static port connect to xrdp session, I mean where I can use same session when ever I connect to my xrdp.Thanks,Gulab Pasha

  • Anonymous
    March 13, 2017
    Thank you very much. It works for me.

    • Anonymous
      March 14, 2017
      You are more than welcome :)
  • Anonymous
    March 19, 2017
    Why do you need to pull the package(s) from the nux desktop rather than the CentOS/EPEL repos?

    • Anonymous
      April 06, 2017
      Hi CJ, not for a specific reason but I prefer nux as it doesn't have any dependencies, it works right away versus EPEL that always gave me trouble.