Skip to content

Instantly share code, notes, and snippets.

@AndyIsHereBoi
Created July 5, 2026 06:45
Show Gist options
  • Select an option

  • Save AndyIsHereBoi/20238681affb7f3ddf6ebbc1ed8fae97 to your computer and use it in GitHub Desktop.

Select an option

Save AndyIsHereBoi/20238681affb7f3ddf6ebbc1ed8fae97 to your computer and use it in GitHub Desktop.
Ubuntu CT auto login
# Yes the script is mostly made using AI
#!/bin/bash
# ==============================================================================
# Script Name: proxmox-lxc-autologin.sh
# Description: Enables automatic root login on Proxmox Ubuntu LXC text consoles.
# Target OS: Ubuntu 24.04 / 25.04 (LXC Container)
# ==============================================================================
# Ensure the script is run as root
if [ "$EUID" -ne 0 ]; then
echo "Error: Please run this script as root or with sudo."
exit 1
fi
echo "=== Starting Proxmox LXC Autologin Setup ==="
# 1. Reset and wipe out any previous failed configuration attempts
echo "[1/4] Cleaning up old configuration files..."
rm -rf /etc/systemd/system/container-getty@*
rm -rf /etc/systemd/system/getty@*
# 2. Create the systemd drop-in directory for container-getty@1
echo "[2/4] Creating systemd service directory..."
TARGET_DIR="/etc/systemd/system/container-getty@1.service.d"
mkdir -p "$TARGET_DIR"
# 3. Inject the clean override configuration
echo "[3/4] Writing new override configuration file..."
cat << 'EOF' > "$TARGET_DIR/override.conf"
[Service]
ExecStart=
ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 $TERM
EOF
# 4. Reload the systemd daemon to pick up the changes
echo "[4/4] Reloading systemd configurations..."
systemctl daemon-reload
echo "=== Setup Complete! ==="
echo "The container will now reboot to apply the automatic root login..."
sleep 2
# Reboot the container
reboot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment