DEV Community

Ricardo Sueiras for AWS

Posted on

5 1 1

Configuring DCV to access Ubuntu Desktop on EC2 with a browser

When I am away from home and on the road, I only have my Macbook and I miss having my Ubuntu desktop machine. In the past I have used Amazon Workspaces but this is more geared towards larger use cases (for example, it requires you setup a directory server). I was looking for a much simpler setup. As I was looking at my options, I came across DCV and decided that this looks like a better fit for what I want to do.

In essence it allows you to have a full linux desktop experience without having to worry about managing RDP tools, as you can just open up a browser, authenticate, and that is it (although DCV does have its own client too if you want).

I am going to share how I got my Ubuntu 24.04 LTS Desktop up and running. If you need other versions (20.04 and 22.04 for example) the instructions will be similar, just you need to change the package versions when installing DCV as these are distribution dependant). You can also use this approach with other Linux distributions as the installation guide covers Amazon Linux, RHEL, Centos, Rocky, and Suse. The packages also cover x86 and Arm.

Setting up my Ubuntu desktop

Here is how I setup my EC2 instance. I initially launched it via the AWS Console, with the following configuration:

  • Choose an instance type with at least 4 vcpu's and 16Gb of ram, with 50GB of storage
  • Deployed this on a VPC in a public subnet
  • Configured the Security group to allow inbound access to just my IP address on ports 22 (SSH) and 8443 (DCV)
  • Added an instance profile that would allow the EC2 instance to have access to Amazon S3 (for the DCV licensing) - see the notes at the end of this post for details

Need a GPU? I could have gone with a GPU based EC2 instance but I am not doing anything that is very graphically intensive, but if you do then I suggest you check out the CloudFormation templates that I link to below that configures all the additional steps needed to support GPU based instances.

After this had started, I ssh'd into the machine and then began following the steps outlined in the installation documentation here. I will outline the steps below:

To set things up, we need to do a few things.

  • update the Ubuntu packages (sudo apt update)
  • install the Ubuntu Desktop packages (sudo apt install ubuntu-desktop)
  • install GDM3 (sudo apt install gdm3)
  • verify that GDM3 is configured (cat /etc/X11/default-display-manager)
  • do another update (sudo apt upgrade) and reboot (sudo reboot)
  • disable Wayland as DCV only supports X11 at the moment (/etc/gdm/custom.conf) and set WaylandEnable=false)
  • restart GDM (sudo systemctl restart gdm3)
  • configure X server to auto start (sudo systemctl get-default)
  • start the X server (sudo systemctl isolate graphical.target)
  • verify that the X server is running (ps aux | grep X | grep -v grep)
  • install glxinfo (sudo apt install mesa-utils)
  • verify that the OpenGL software rendering is working (sudo DISPLAY=:0 XAUTHORITY=$(ps aux | grep "X.-auth" | grep -v Xdcv | grep -v grep | sed -n 's/.-auth ([^ ]+).*/\1/p') glxinfo | grep -i "opengl.*version")
  • install XDummy drivers as I am not using a GPU instance (sudo apt install xserver-xorg-video-dummy)
  • create a xorg.conf file using the info here
  • restart services (sudo systemctl isolate multi-user.target and sudo systemctl isolate graphical.target)

Now that we have this setup, we can install DCV

  • grab the DCV certificates (wget https://d1uj6qtbmh3dt5.cloudfront.net/NICE-GPG-KEY and gpg --import NICE-GPG-KEY)
  • get the installation packages (wget https://d1uj6qtbmh3dt5.cloudfront.net/2024.0/Servers/nice-dcv-2024.0-18131-ubuntu2404-x86_64.tgz)
  • extract the packages (tar -xvzf nice-dcv-2024.0-18131-ubuntu2404-x86_64.tgz && cd nice-dcv-2024.0-18131-ubuntu2404-x86_64)
  • install DCV packages (sudo apt install ./nice-dcv-server_2024.0.18131-1_amd64.ubuntu2404.deb)
  • install additional DCV packages (sudo apt install ./nice-dcv-web-viewer_2024.0.18131-1_amd64.ubuntu2404.deb - and you can also install nice-xdcv_2024.0.631-1_amd64.ubuntu2404.deb / nice-dcv-gl_2024.0.1078-1_amd64.ubuntu2404.deb, and nice-dcv-gltest_2024.0.344-1_amd64.ubuntu2404.deb)
  • add dcv user to the video group (sudo usermod -aG video dcv)
  • set the user credentials for your Ubuntu Desktop box (sudo passwd ubuntu)
  • edit the "/etc/dcv/dcv.conf" file to update/add the following entriesd
[session-management]
create-session = true

[session-management/automatic-console-session]
owner = "ubuntu"

[connectivity]
quic-listen-endpoints=['0.0.0.0:8443', '[::]:8443']
web-listen-endpoints=['0.0.0.0:8443', '[::]:8443']

enable-quic-frontend=true
Enter fullscreen mode Exit fullscreen mode
  • check to make sure that DCV has access to X by running (sudo DISPLAY=:0 XAUTHORITY=$(ps aux | grep "X.-auth" | grep -v Xdcv | grep -v grep | sed -n 's/.-auth ([^ ]+).*/\1/p') xhost | grep "SI:localuser:dcv$") and checking the output (should be SI:Local:dcv)
  • enable DCV to auto start (sudo systemctl enable dcvserver)
  • reboot (sudo reboot)

This should take you about 5-10 minutes to complete. Once the system has restarted, you can open up a web browser and in the address bar go to -> "https://{IP address of your EC2 instance}:8443"

You will get an SSL certificate error, but bypass that and you should then see the DCV login screen. Enter "ubuntu" as the username and then use the password you configured. After a few seconds, you should see your Ubuntu Desktop appear.

Here is a short video that I recorded whilst I was putting this together.

You will notice that I recorded this on the train heading into London (so apologies for the background noise!)

dcv client install (optional)

There is a dedicated DCV client that you can install if you prefer to use that instead of a web browser. There are downloads available for Windows, MacOS, and Linux. These offer support for things like desktop sharing, device support, etc.

If that sounds of interest, you can check them out and download the DCV clients here

Automating this via CloudFormation

I did manage to find a CloudFormation template that automates all these steps. You can review it here. I did not use this, but it is referenced from the official DCV documentation pages so it should be good to go. It looks a lot more comprehensive that the steps I took, so if you want a more robust setup then I suggest you look at this.

Gotchas

When I first followed the setup everything worked but when I went to connect, it would just hang. After spending a while trying to figure out what the issue was, it turns out it was both simple and a case of RTFM! When implementing DCV, you need to ensure that your EC2 instance has permissions to access Amazon S3, as this is how it manages its licensing. You can read about that here. Once I did this it all worked perfectly.

Creating instance profiles using Amazon Q Developer

I thought I would use Amazon Q Developer CLI to help me create the IAM instance profile to attach to my EC2 instances that would provide access to DCV licensing. In about two minutes I had not just the policies, but also scripts to implement these. I am sharing the output, but if you have not already tried it, it is one of the best tools in any AWS Builders hands - I share details on how to get started at the end of this post.

Below is a simple IAM policy that grants the necessary permissions for using NICE DCV on an EC2 instance:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "s3:GetObject",
        "s3:PutObject"
      ],
      "Resource": "arn:aws:s3:::dcv-license.*/*"
    },
    {
      "Effect": "Allow",
      "Action": [
        "ec2:DescribeInstances",
        "ec2:DescribeTags"
      ],
      "Resource": "*"
    },
    {
      "Effect": "Allow",
      "Action": [
        "cloudwatch:PutMetricData"
      ],
      "Resource": "*"
    }
  ]
}
Enter fullscreen mode Exit fullscreen mode

I copied this to a file (dcv-policy.json) and saved it. I was then able to use this with the help of the AWS cli. (you will need to change this for your own AWS Account details)

aws iam create-policy \
    --policy-name DCVInstancePolicy \
    --policy-document file://dcv-policy.json

aws iam create-role \
    --role-name DCVInstanceRole \
    --assume-role-policy-document '{
      "Version": "2012-10-17",
      "Statement": [
        {
          "Effect": "Allow",
          "Principal": {
            "Service": "ec2.amazonaws.com"
          },
          "Action": "sts:AssumeRole"
        }
      ]
    }'

aws iam attach-role-policy \
    --role-name DCVInstanceRole \
    --policy-arn arn:aws:iam::XXXXXXX:policy/DCVInstancePolicy

aws iam create-instance-profile \
    --instance-profile-name DCVInstanceProfile

aws iam add-role-to-instance-profile \
    --instance-profile-name DCVInstanceProfile \
    --role-name DCVInstanceRole
Enter fullscreen mode Exit fullscreen mode

This then generates "DCVInstanceProfile" which you can then attach to your EC2 instance.

Conclusion

In this post I shared how I setup an EC2 instance of Ubuntu so that I could use the Desktop, creating a simplified experience that allows me to access this anywhere with just a browser. You can try this for yourself by checking out the Cloudformation templates I shared above. I also showed how I was able to use Amazon Q Developer CLI to quickly address creating some of the IAM policies I needed.
You can get started using this for free by signing up for a Builder ID and then downloading/installing the tool from here.

Heroku

Built for developers, by developers.

Whether you're building a simple prototype or a business-critical product, Heroku's fully-managed platform gives you the simplest path to delivering apps quickly — using the tools and languages you already love!

Learn More

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

If you found this post useful, please drop a ❤️ or a friendly comment!

Okay.