Last active
August 21, 2025 10:42
-
-
Save cicorias/0b0765c8ff558cda421782f69c60b130 to your computer and use it in GitHub Desktop.
setting up RDP for Ubuntu Server 24.04
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
| sudo ip addr flush dev eth0 | |
| sudo ip addr add 10.1.1.1/24 dev eth0 | |
| sudo ip link set eth0 up | |
| sudo ip route add default via 10.1.1.1 |
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
| #!/usr/bin/env bash | |
| set -euo pipefail | |
| DEST="$HOME/installer-saved" | |
| ISO_MNT="/mnt/iso" | |
| ISO_IMG="ubuntu-24.04.3-live-server-amd64.iso" | |
| echo "[*] Creating destination folder at $DEST..." | |
| mkdir -p "$DEST" | |
| # 1. Copy installer logs (works after installation or during live install) | |
| if [ -d /var/log/installer ]; then | |
| echo "[*] Copying installer logs..." | |
| cp -r /var/log/installer "$DEST/" | |
| fi | |
| # 2. If ISO is available locally, mount it and copy grub + casper | |
| if [ -f "$ISO_IMG" ]; then | |
| echo "[*] Mounting ISO..." | |
| sudo mkdir -p "$ISO_MNT" | |
| sudo mount -o loop "$ISO_IMG" "$ISO_MNT" | |
| echo "[*] Copying GRUB config..." | |
| mkdir -p "$DEST/grub" | |
| cp -v "$ISO_MNT/boot/grub/grub.cfg" "$DEST/grub/" | |
| echo "[*] Copying casper directory..." | |
| mkdir -p "$DEST/casper" | |
| cp -av "$ISO_MNT/casper/"* "$DEST/casper/" | |
| echo "[*] Unmounting ISO..." | |
| sudo umount "$ISO_MNT" | |
| sudo rmdir "$ISO_MNT" | |
| else | |
| echo "[!] ISO image not found at $ISO_IMG" | |
| echo " Place the ISO in current directory or update the script." | |
| fi | |
| # 3. Extract initrd to inspect casper scripts | |
| INITRD="$DEST/casper/initrd" | |
| if [ -f "$INITRD" ]; then | |
| echo "[*] Extracting casper initrd..." | |
| mkdir -p "$DEST/initrd-extracted" | |
| ( | |
| cd "$DEST/initrd-extracted" | |
| zcat "$INITRD" | cpio -idmv || true | |
| ) | |
| fi | |
| # 4. Create archive while keeping originals | |
| ARCHIVE="$HOME/installer-saved.tar.gz" | |
| echo "[*] Creating archive $ARCHIVE..." | |
| tar -czf "$ARCHIVE" -C "$HOME" "installer-saved" | |
| echo "[*] Done!" | |
| echo " Directory: $DEST" | |
| echo " Archive: $ARCHIVE" |
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
| #!/usr/bin/env bash | |
| set -euo pipefail | |
| ### === Edit these if needed === | |
| PXE_SERVER_IP="10.1.1.1" # static IP for eth0 | |
| NETWORK_INTERFACE="eth0" # private/PXE NIC | |
| export NETMASK="255.255.255.0" # netmask for eth0 -- pyton process needs this | |
| PUBLIC_INTERFACE="eth1" # DHCP NIC | |
| DNS_SERVERS="8.8.8.8,8.8.4.4" # leave empty to rely on DHCP’s DNS | |
| NETPLAN_FILE="/etc/netplan/01-dual-nic.yaml" | |
| ### ============================ | |
| # Convert mask -> CIDR using python3 (no dependencies) | |
| PREFIX=$( | |
| python3 - <<'PY' | |
| import os | |
| m=os.environ["NETMASK"] | |
| print(sum(bin(int(o)).count("1") for o in m.split("."))) | |
| PY | |
| ) | |
| ADDR_CIDR="${PXE_SERVER_IP}/${PREFIX}" | |
| # Build YAML (no read -d '') | |
| YAML=$(cat <<EOF | |
| # Generated by setup-dual-nic-clean.sh | |
| network: | |
| version: 2 | |
| renderer: networkd | |
| ethernets: | |
| ${NETWORK_INTERFACE}: | |
| dhcp4: false | |
| dhcp6: false | |
| addresses: [ "${ADDR_CIDR}" ] | |
| $( [ -n "${DNS_SERVERS}" ] && echo " nameservers: { addresses: [ $(echo "${DNS_SERVERS}" | sed 's/,/ , /g') ] }" ) | |
| optional: true | |
| ${PUBLIC_INTERFACE}: | |
| dhcp4: true | |
| dhcp6: false | |
| dhcp4-overrides: | |
| route-metric: 100 | |
| optional: true | |
| EOF | |
| ) | |
| echo "CIDR computed: ${ADDR_CIDR}" | |
| # Backup any existing files to avoid conflicts (like 50-cloud-init.yaml) | |
| sudo mkdir -p /etc/netplan/backup | |
| for f in /etc/netplan/*.yaml; do | |
| [ -e "$f" ] && sudo cp -a "$f" "/etc/netplan/backup/$(basename "$f").bak" | |
| done | |
| # Write atomically | |
| tmpfile=$(mktemp) | |
| printf "%s\n" "$YAML" > "$tmpfile" | |
| sudo mv "$tmpfile" "$NETPLAN_FILE" | |
| sudo chmod 600 "$NETPLAN_FILE" | |
| echo "===== Wrote $NETPLAN_FILE =====" | |
| sudo cat "$NETPLAN_FILE" | |
| echo "================================" | |
| # Bring links up just in case | |
| sudo ip link set "$NETWORK_INTERFACE" up || true | |
| sudo ip link set "$PUBLIC_INTERFACE" up || true | |
| echo | |
| echo "Generating with debug..." | |
| sudo netplan --debug generate | |
| echo | |
| echo "Trying apply with rollback..." | |
| sudo netplan try || { echo "netplan try failed/rolled back"; exit 1; } | |
| echo | |
| sudo netplan apply | |
| echo "Applied." | |
| echo | |
| echo "IPv4 addresses:" | |
| ip -4 -o a | sed 's/^[0-9]*: //' | |
| echo | |
| echo "Routes:" | |
| ip route |
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
| #!/usr/bin/env bash | |
| # | |
| # setup-gnome-xrdp.sh | |
| # Installs GNOME desktop and xRDP on Ubuntu 24.04 Server | |
| # Usage: sudo bash setup-gnome-xrdp.sh | |
| # | |
| set -euo pipefail | |
| log() { | |
| echo -e "\n[INFO] $1\n" | |
| } | |
| if [[ $EUID -ne 0 ]]; then | |
| echo "[ERROR] This script must be run as root (try: sudo $0)" | |
| exit 1 | |
| fi | |
| log "Updating package lists..." | |
| apt update | |
| log "Installing GNOME desktop (Ubuntu flavor)..." | |
| # For a lighter, vanilla GNOME: replace 'ubuntu-desktop' with 'vanilla-gnome-desktop' | |
| apt install -y ubuntu-desktop | |
| log "Installing xRDP..." | |
| apt install -y xrdp | |
| log "Enabling and starting xRDP service..." | |
| systemctl enable xrdp | |
| systemctl start xrdp | |
| log "Configuring default session to GNOME..." | |
| echo gnome-session > /home/$SUDO_USER/.xsession | |
| chown $SUDO_USER:$SUDO_USER /home/$SUDO_USER/.xsession | |
| log "Adding $SUDO_USER to ssl-cert group..." | |
| adduser "$SUDO_USER" ssl-cert | |
| if command -v ufw &>/dev/null; then | |
| log "Allowing RDP through UFW firewall..." | |
| ufw allow 3389/tcp || true | |
| else | |
| log "UFW not installed; skipping firewall config." | |
| fi | |
| log "Done! Connect via RDP to:" | |
| hostname -I | awk '{print $1":3389"}' | |
| echo -e "\nYou can now log in with your Ubuntu username and password via Remote Desktop.\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment