LoginSignup
3
3

More than 3 years have passed since last update.

Mac から GCPのUbuntu Desktop に Microsoft Remote Desktop でログインする

Posted at

LANの中のデスクトップ環境を再現したいのだが、自宅や会社のネットワークの設定は自由度がない(というかぶっ壊したら大変だ)ので、壊しても困らないIaaSで。Mac から GCPのUbuntu Desktop に Microsoft Remote Desktop でログインするまでの道のりをまとめておく。

免責事項

実際に運用するなら、IAM や Access Context Managerで制御したり、リモート側のOSの設定もちゃんと考える必要あり。あくまで個人検証用ということで。

利用環境

  • ローカル: Mac OS + Microsoft Remote Desktop アプリ
  • 通信: Identity-aware Proxy で RDP トラフィックをトンネリング
  • リモート: Ubuntu 20.04(GCP) に xrdp をインストール

構築方法

1. GCP

外部IPで3389を晒すのは危ういので、GCEインスタンスで外部IPを設定せずに、Identity-aware ProxyのTCP 転送での IAP の使用を採用した。

VPC、Firewall、Router、Cloud-Natの設定などは出尽くしているので、割愛。
GCEインスタンスは startup-script を用意しておき、 gcloud コマンドで作成する。

真面目にやるなら、事前にイメージを作成しておくべし。

#! /bin/bash
sudo apt update
sudo apt -y upgrade

sudo apt -y install ubuntu-desktop xrdp
sudo systemctl enable xrdp
sudo systemctl start xrdp

sudo useradd ${DESKTOP_USER} --create-home --shell /bin/bash
echo "${DESKTOP_USER}:${DESKTOP_PASSWORD}" | sudo chpasswd
sudo gpasswd -a ${DESKTOP_USER} sudo

cat <<EOF | sudo tee /etc/polkit-1/localauthority/50-local.d/xrdp-color-manager.pkla  
[Netowrkmanager]  
Identity=unix-user:*  
Action=org.freedesktop.color-manager.create-device  
ResultAny=no  
ResultInactive=no  
ResultActive=yes  
EOF
export DESKTOP_USER=your_user
export DESKTOP_PASSWORD=your_password

gcloud compute instances create ubuntu-desktop \
    --machine-type n1-standard-1 \
    --image-project ubuntu-os-cloud \
    --image-family ubuntu-2004-lts \
    --network=desktop-vpc \
    --subnet=desktop-subnet-1 \
    --zone=us-west1-a \
    --no-address \
    --tags=ssh,rdp \
    --metadata startup-script="$(cat startup-script.sh | envsubst)"

envsubst で startup-script の変数を置き換えてる。

2. IAP Tunnel

GCEを起動後に apt が走るので、それなりの時間が経過したら IAP Tunnel を開く。

gcloud compute start-iap-tunnel ubuntu-desktop 3389 \
    --local-host-port=localhost:3389 \
    --zone=us-west1-a

これでローカルマシンからIAPを経由して、外部IPアドレスが設定されてないインスタンスにアクセスできるようになる。
Firewallで IAPのIP Rangesからのアクセスを許可しておくのは言わずもがな。

3. Microsoft Remote Desktop

RDPプロトコルに対応してればたぶんなんでもいいんだが、 Microsoft Remote Desktopを使うことにした。

使い方は "Add PC" して、"PC name" に localhost を設定すればよい。
"User account" は インスタンス作成時に指定したユーザーとパスワードを設定する。

スクリーンショット 2020-08-02 10.59.41.png

動作確認

Ubuntu Desktopにログインできたので、Firefoxで What is my IP Addreess? で確認してみた。

IMG20200802104016.jpg

us-west1 を選択したので、想定通り。

参考

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3