Skip to content

Instantly share code, notes, and snippets.

@djravine
Last active April 9, 2020 02:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djravine/2479d7f14acb3e4ef155179f155010b2 to your computer and use it in GitHub Desktop.
Save djravine/2479d7f14acb3e4ef155179f155010b2 to your computer and use it in GitHub Desktop.
Setup xRDP on Ubuntu 18.04
#!/bin/bash
set -xuo pipefail
# GIST: https://gist.github.com/djravine/2479d7f14acb3e4ef155179f155010b2
# USAGE: ssh -t -p 2222 adan@localhost 'curl -sL https://gist.github.com/djravine/2479d7f14acb3e4ef155179f155010b2/raw | sudo bash -s -- USERNAME PASSWORD'
# CHECK USERNAME/PASSWORD
USERNAME=$1
PASSWORD=$2
# SET LOCALE
LOCALE="en_AU.UTF-8"
LOCALE_ALT="en_AU en_GB.UTF-8 en_GB en_US.UTF-8 en_US"
LANGUAGE="en_AU:en_GB:en"
locale-gen $LOCALE $LOCALE_ALT
update-locale LANG=$LOCALE
update-locale LANGUAGE=$LANGUAGE
update-locale LC_ALL=$LOCALE
update-locale LC_NUMERIC=$LOCALE
update-locale LC_TIME=$LOCALE
update-locale LC_MONETARY=$LOCALE
update-locale LC_PAPER=$LOCALE
update-locale LC_IDENTIFICATION=$LOCALE
update-locale LC_NAME=$LOCALE
update-locale LC_ADDRESS=$LOCALE
update-locale LC_TELEPHONE=$LOCALE
update-locale LC_MEASUREMENT=$LOCALE
dpkg-reconfigure --frontend noninteractive locales
# ADD NEW USER
echo -e "${PASSWORD}\n${PASSWORD}" | adduser ${USERNAME}
mkdir -p /home/${USERNAME}/.ssh
chmod 700 /home/${USERNAME}/.ssh
cp ~/.ssh/authorized_keys /home/${USERNAME}/.ssh/authorized_keys
chmod 600 /home/${USERNAME}/.ssh/authorized_keys
chown -R ${USERNAME}:${USERNAME} /home/${USERNAME}/.ssh
adduser ${USERNAME} sudo
if [ -f /etc/sudoers.d/99-${USERNAME} ]; then
rm -f /etc/sudoers.d/99-${USERNAME}
fi
cat << EOF >> /etc/sudoers.d/99-${USERNAME}
# User rules for ${USERNAME}
${USERNAME} ALL=(ALL) NOPASSWD:ALL
EOF
# INSTALL SOFTWARE
apt-get update
apt-get install -y \
ubuntu-desktop \
xrdp \
xorgxrdp \
xfonts-base \
xfonts-75dpi \
xfonts-100dpi \
xfce4 \
xfce4-goodies
apt-get autoremove -y
# SET SESSION MANGER
if [ -f /home/${USERNAME}/.xsession ]; then
rm -f /home/${USERNAME}/.xsession
fi
echo xfce4-session > /home/${USERNAME}/.xsession
chown ${USERNAME}:${USERNAME} /home/${USERNAME}/.xsession
chmod +x /home/${USER}/.xsession
# RUN BASH NOT SH
sed -i "s|#\!/bin/sh|#\!/bin/bash|g" /etc/X11/Xsession
# ADD XRDP USER TO SSL-CERT GROUP
adduser xrdp ssl-cert
# RESTART XRDP
service xrdp restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment