Notes

Connect from macOS to Ubuntu remote desktop using xfreerdp and GNOME Remote Desktop

Connect to remote graphical desktop sessions over the network using RDP

Edit on GitHub

System Administration
4 minutes

tested on:

  • macOS version: Tahoe 26.3.1
  • Ubuntu version: 24.04 LTS

what we are going to do:

  • configure gnome-remote-desktop as a server on Ubuntu
  • install xfreerdp as a client on macOS
  • save login details to macOS keychain
  • create a shell function to connect to the server

notes:

  • only one GUI session can be open at a time. If you are connecting via RDP to the user and the user is already logged into a graphical interface locally on that machine, a new connection will be denied. You will have to close the existing GUI session and then connect again. read more

Ubuntu setup (server)

On Ubuntu, i.e. the machine you want to remotely access, you need to enable remote desktop sharing and create credentials

GNOME Remote Desktop is the official built-in remote desktop server for the GNOME desktop environments, supporting both RDP (Remote Desktop Protocol) and VNC. It comes pre-installed on Ubuntu 24.04

 1# install Windows Portable Runtime library command line utilities
 2# we need winpr-makecert, which is a tool to create X.509 certificates.
 3sudo apt install gnome-remote-desktop winpr-utils
 4
 5RDP_USER="queen"
 6RDP_PASS="6f4db001"
 7
 8sudo -u gnome-remote-desktop winpr-makecert \
 9    -silent -rdp -path ~gnome-remote-desktop rdp-tls
10sudo grdctl --system rdp enable
11sudo grdctl --system rdp set-credentials "${RDP_USER}" "${RDP_PASS}"
12sudo grdctl --system rdp set-tls-key ~gnome-remote-desktop/rdp-tls.key
13sudo grdctl --system rdp set-tls-cert ~gnome-remote-desktop/rdp-tls.crt
14sudo systemctl --now enable gnome-remote-desktop.service

Change the username and password above to whatever credentials you want to create. You will use these to connect to this machine from macOS.

Next, make sure the RDP port is open in firewall:

1sudo ufw status
2
3sudo ufw allow 3389/tcp

macOS setup (client)

1# install the FreeRDP package on macOS
2brew install freerdp
3
4# install XQuartz for X11 support on macOS
5brew install --cask xquartz
6
7# LOGOUT and log back in, then confirm that xquartz is running
8echo $DISPLAY
9# /private/tmp/com.apple.launchd.xxxxx/org.xquartz:0

Once you have an X server running, you can connect to the Ubuntu machine using xfreerdp

1# connect 
2xfreerdp /v:100.80.70.110:3389 /u:'queen' /cert:tofu

where 100.80.70.110 is the IP of the machine you are connecting to (host), and 3389 is the default port for RDP connections. /cert:tofu tells it to trust the certificate on first use, and alert if the certificate fingerprint ever changes again.

(Using /cert:tofu is better than /cert:ignore but if you have the time, you should set it up to use either /cert:fingerprint:.. or add the ubuntu machine’s self-signed certificate to the macOS System Keychain as a trusted certificate)

xfreerdp is a command-line Remote Desktop Protocol (RDP) client for X11 part of the FreeRDP project.

Save credentials to keychain

Save the credentials to macOS keyhchain so that you don’t have to enter the password every time

1# add password
2security add-generic-password -a "queen" -s "Rocker RDP" -w
3
4# confirm
5security find-generic-password -a "queen" -s "Rocker RDP"

queen here is the username i specified when creating RDP credentials on Ubuntu. You can now use the password like so:

1security find-generic-password \
2    -a "queen" \
3    -s "Rocker RDP" \
4    -w | xfreerdp \
5    /v:100.80.70.110:3389 \
6    /u:"queen" \
7    /cert:tofu \
8    /from-stdin:force

Create a shell function to connect to the server using an alias

Add this to the end of you ~/.zshrc file

 1# Connect via RDP to Ubuntu desktop sharing (Rocker machine)
 2# command: 
 3#       xfreerdp /v:100.80.70.110:3389 /u:'queen' /cert:tofu
 4# Takes credentials saved in macOS keychain, save credentials with:
 5#       security add-generic-password -a "queen" -s "Rocker RDP" -w
 6rocker-rdp() {
 7    local RDP_HOST="100.80.70.110:3389"
 8    local RDP_USER="queen"
 9    local KEYCHAIN_SERVICE="Rocker RDP"
10
11    local password
12
13    # Retrieve the password securely from macOS Keychain.
14    password=$(security find-generic-password \
15        -a "$RDP_USER" \
16        -s "$KEYCHAIN_SERVICE" \
17        -w) || {
18        echo "Could not retrieve RDP password from Keychain" >&2
19        return 1
20    }
21
22    # Connect using the password from Keychain.    
23    # Pass the password through stdin rather than putting it
24    # directly on the command line.
25    #
26    # /cert:tofu = Trust On First Use.
27    # The first certificate is remembered. If the server later
28    # presents a different certificate, FreeRDP warns/refuses
29    # instead of silently accepting it.
30    printf '%s\n' "$password" | xfreerdp \
31        /v:"$RDP_HOST" \
32        /u:"$RDP_USER" \
33        /cert:tofu \
34        /from-stdin:force
35}

Load the changes

1source ~/.zshrc

Now you can run rocker-rdp from the terminal and it should connect and open the login page up your remote desktop

Related

Browse all topics