動かざることバグの如し

近づきたいよ 君の理想に

Ubuntu Desktop環境でMacOSからリモートデスクトップ接続したい

環境

  • Ubuntu 24.04

やりたいこと

以前はxrdpを使っていたがUbuntu 26.04からX11が廃止されてWaylandになった。そのためX11前提のxrdpが動かなくなってしまった。 そこで今回はGNOME Remote Desktopを使ってリモートデスクトップを設定する。

uepon.hatenadiary.com

最初からUbuntuDesktopの場合は特にインストールするものはない。

VPSなどubuntu serverの場合はapt install ubuntu-desktop-minimal でデスクトップ環境を一発で入れられる。

手順

まずはxrdp含めて既存でRDPサーバーが起動してないことを確認する。もしxrdpなどが動いていれば停止しておく。

ss -tlnp | grep 3389

次に、既存の認証情報をクリアしておく。

sudo grdctl --system rdp clear-credentials

RDP接続に必要なTLS証明書を配置するためのディレクトリを作成する。

sudo mkdir -p /var/lib/gnome-remote-desktop/.local/share/gnome-remote-desktop
cd /var/lib/gnome-remote-desktop/.local/share/gnome-remote-desktop

TLS証明書と秘密鍵を生成する。入力を省略するために -subj オプションをつけて一気に生成する。

sudo openssl req -new -x509 -nodes -newkey ec:<(openssl ecparam -name secp384r1) -keyout tls.key -out tls.crt -days 3650 -subj "/C=JP/O=Local/CN=ubuntu"

作成した証明書を gnome-remote-desktop ユーザーが読み込めるように所有権を変更する。

sudo chown -R gnome-remote-desktop:gnome-remote-desktop /var/lib/gnome-remote-desktop/.local

grdctl コマンドを使ってシステムレベルのRDP設定を行う。証明書のパスを登録する。 実行時に「TPM credentials failed」という警告が出るが、システムが代替手段(GKeyFile)にフォールバックしてくれるため無視して構わない。

sudo grdctl --system rdp set-tls-key /var/lib/gnome-remote-desktop/.local/share/gnome-remote-desktop/tls.key
Init TPM credentials failed because Failed to initialize transmission interface context: tcti:IO failure, using GKeyFile as fallback.
sudo grdctl --system rdp set-tls-cert /var/lib/gnome-remote-desktop/.local/share/gnome-remote-desktop/tls.crt
Init TPM credentials failed because Failed to initialize transmission interface context: tcti:IO failure, using GKeyFile as fallback.

リモートデスクトップに接続する際に入力するユーザー名とパスワードを設定する。 OSのログインユーザーとは別になるので注意

sudo grdctl --system rdp set-credentials 任意のユーザー名 任意のパスワード

RDPを有効にしてサービスを再起動する。

sudo grdctl --system rdp enable
sudo systemctl daemon-reload
sudo systemctl restart gnome-remote-desktop

ステータスを確認する。 Unit status: active になっていればOK

sudo grdctl --system status
Init TPM credentials failed because Failed to initialize transmission interface context: tcti:IO failure, using GKeyFile as fallback.
Overall:
    Unit status: active
RDP:
    Status: enabled
    Port: 3389
    TLS certificate: (null)
    TLS fingerprint: (null)
    TLS key: (null)
    Username: (hidden)
    Password: (hidden)

あとファイアウォール(ufwなど)で3389番ポートの許可を忘れずに設定しておくこと。

接続できないエラー

MacOSでRDPリモートデスクトップ接続しようとするとエラーになって接続できない。

Your session was disconnected
We couldn't connect to the remote PC. This might be due to an expired password.
If this keeps happening, contact your network administrator for assistance.
Error code: 0x207

解決策としては、Windowsリモートデスクトップ側でエクスポートし、テキストエディタで開いて以下の箇所を0から1にする。

-use redirection server name:i:0
+use redirection server name:i:1

よきUbuntuライフを。

参考リンク