Created
February 21, 2023 20:08
-
-
Save alfonmga/fa4783822c7841ed6aa35e9090162d8b to your computer and use it in GitHub Desktop.
Deploy an Ubuntu 22.04 LTS Desktop on Google Cloud Platform with RDP ready.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -e | |
# Zone | |
ZONE=europe-west8-a | |
echo "Destroying cloud Ubuntu Desktop..." | |
gcloud compute instances delete ubuntu-desktop --zone=$ZONE --quiet | |
gcloud compute firewall-rules delete allow-rdp --quiet | |
echo "Cloud Ubuntu Desktop destroyed!" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -e | |
# Zone | |
ZONE="europe-west8-a" | |
MACHINE_TYPE="n2-standard-4" | |
echo "Deploying cloud Ubuntu Desktop (Ubuntu 20.04 LTS)..." | |
gcloud compute instances create ubuntu-desktop \ | |
--zone=$ZONE \ | |
--machine-type=$MACHINE_TYPE \ | |
--image-project=ubuntu-os-cloud \ | |
--image-family=ubuntu-2204-lts \ | |
--boot-disk-size=50 \ | |
--boot-disk-type=pd-ssd \ | |
--tags=http-server,https-server \ | |
--metadata=startup-script='#! /bin/bash | |
sudo apt-get update | |
sudo apt-get install -y ubuntu-desktop-minimal | |
sudo apt-get install -y xrdp | |
sudo systemctl enable xrdp | |
sudo systemctl start xrdp | |
sudo ufw allow 3389/tcp | |
' | |
EXTERNAL_IP=$(gcloud compute instances describe ubuntu-desktop --zone=$ZONE --format='get(networkInterfaces[0].accessConfigs[0].natIP)') | |
# Create a firewall rule to allow RDP connections to the VM if it doesn't exist | |
if ! gcloud compute firewall-rules describe allow-rdp; then | |
gcloud compute firewall-rules create allow-rdp \ | |
--allow tcp:3389 \ | |
--target-tags http-server,https-server | |
fi | |
# Wait for the VM to be ready to accept SSH connections | |
while ! nc -z $EXTERNAL_IP 22; do | |
echo "Waiting for the VM to be ready to accept SSH connections..." | |
sleep 5 | |
done | |
# Connect to the VM SSH and change the root password to alfon | |
echo "Changing the root password to alfon..." | |
gcloud compute ssh ubuntu-desktop --zone=$ZONE --command="sudo su -c 'passwd << EOF | |
alfon | |
alfon | |
EOF'" | |
echo "Root password changed!" | |
# Wait for the VM to be ready to accept RDP connections | |
while ! nc -z $EXTERNAL_IP 3389; do | |
echo "Waiting for the VM to be ready to accept RDP connections..." | |
sleep 5 | |
done | |
echo "Cloud Ubuntu desktop deployed!" | |
echo "Connect to it using RDP at $EXTERNAL_IP:3389 with user root and password alfon" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment