Created
May 19, 2024 18:59
-
-
Save devinci-it/d7907c5cd63800d09e0147f04524cbef to your computer and use it in GitHub Desktop.
This script installs and configures XRDP with XFCE on a Debian system.
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/bash | |
| # This script installs and configures XRDP with XFCE on a Debian system. | |
| # | |
| # It performs the following steps: | |
| # 1. Updates the system packages. | |
| # 2. Installs XRDP. | |
| # 3. Installs the XFCE desktop environment. | |
| # 4. Configures XRDP to use XFCE by creating a .xsession file in the home directory. | |
| # 5. Checks if the XRDP_PORT environment variable is set: | |
| # - If XRDP_PORT is set, it configures XRDP to use this port. | |
| # - If XRDP_PORT is not set, it defaults to port 3389. | |
| # 6. Updates the XRDP configuration to use the specified port. | |
| # 7. Restarts the XRDP service to apply the changes. | |
| # 8. Configures the firewall to allow traffic on the specified XRDP port. | |
| # 9. Checks the status of the XRDP service to ensure it's running properly. | |
| # | |
| # Usage: | |
| # - Save this script to a file, e.g., setup_xrdp.sh. | |
| # - Make the script executable: chmod +x setup_xrdp.sh | |
| # - Run the script with superuser privileges: | |
| # sudo ./setup_xrdp.sh | |
| # - Optionally, set the XRDP_PORT environment variable to specify a custom port: | |
| # sudo XRDP_PORT=3390 ./setup_xrdp.sh | |
| # Function to check if XRDP_PORT is set | |
| check_xrdp_port() { | |
| if [ -z "$XRDP_PORT" ]; then | |
| echo "XRDP_PORT is not set. Using default port 3389." | |
| XRDP_PORT=3389 | |
| else | |
| echo "Using XRDP_PORT from environment: $XRDP_PORT" | |
| fi | |
| } | |
| # Update the system | |
| echo "Updating the system..." | |
| sudo apt update && sudo apt upgrade -y | |
| # Install XRDP | |
| echo "Installing XRDP..." | |
| sudo apt install -y xrdp | |
| # Install XFCE | |
| echo "Installing XFCE..." | |
| sudo apt install -y xfce4 xfce4-goodies | |
| # Configure XRDP to use XFCE | |
| echo "Configuring XRDP to use XFCE..." | |
| echo xfce4-session > ~/.xsession | |
| # Check XRDP_PORT and configure XRDP to use it | |
| check_xrdp_port | |
| # Update the XRDP configuration to use the specified port | |
| echo "Configuring XRDP to listen on port $XRDP_PORT..." | |
| sudo sed -i "s/3389/$XRDP_PORT/g" /etc/xrdp/xrdp.ini | |
| # Restart XRDP service | |
| echo "Restarting XRDP service..." | |
| sudo systemctl restart xrdp | |
| # Configure firewall to allow XRDP traffic | |
| echo "Configuring firewall..." | |
| sudo ufw allow ${XRDP_PORT}/tcp | |
| # Check XRDP service status | |
| echo "Checking XRDP service status..." | |
| sudo systemctl status xrdp | |
| echo "XRDP installation and configuration completed." | |
| echo "You can now connect to your Debian machine using an RDP client on port $XRDP_PORT." | |
| # Exit the script | |
| exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment