Skip to content

Latest commit

 

History

10 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

ssh-gui-login

Simple Shell script that takes advantage of display manager's autologin feature to log a user into the graphical session without having physical access to the machine.

Useful for machines with no monitor/keyboard attached (or one you don't want to walk over to) where you need the display manager to bring up a full GUI session once - for example to unlock a session for VNC/RDP, or to get a desktop running for automated testing - without leaving passwordless login enabled afterward.

How it works

  1. Writes a one-shot autologin config for the target display manager.
  2. Restarts the display manager service.
  3. Polls for the desktop process (e.g. plasmashell) to appear under the target user.
  4. Waits a short grace period once detected.
  5. Deletes the autologin config.

Requirements

  • Must be run as root (or via sudo) on the target machine, typically invoked over SSH.
  • systemctl (script restarts the display manager via systemd).
  • The relevant display manager already installed and configured as the active one.

Configuration

Set via environment variables when invoking the script or configure at the configuration sction at the top of the script (recommended):

Variable Default Description
GUI_LOGIN_USER user (YOU MUST PROBABLY NEED TO CHANGE) The local user to log in as

Other tunables (timeout, poll interval, grace period) are constants near the top of the script and can be edited directly if needed.

Usage

After configuring the script, user, display manager and desktop environment.

To log into a graphical session via ssh you can run the following, replacing user with the user to log in as and target-host with the address to the machine to log in to.

scp gui-login.sh user@target-host:/home/user/
ssh -t user@target-host 'sudo GUI_LOGIN_USER=user bash /home/user/gui-login.sh'

The script should also work in other scenarios as long as you configure it correctly and run it as root.

Display manager support

The display manager's config path, session name, and desktop process name need to be configured at the top section of the script to match the display manager actually in use.

Below are presets for some supported combinations.

SDDM (KDE Plasma)
# Configuration
GUI_LOGIN_USER="${GUI_LOGIN_USER:-user}"
AUTOLOGIN_CONFIG_DIR="/etc/sddm.conf.d"
AUTOLOGIN_CONFIG_FILE="$AUTOLOGIN_CONFIG_DIR/autologin-autogenerated.conf"
SESSION="plasma.desktop"
DESKTOP_PROCESS="plasmashell"
CONFIG_FILE_TEMPLATE="[Autologin]
User=$GUI_LOGIN_USER
Session=$SESSION"
WAIT_TIMEOUT="60"
GRACE_PERIOD="2"
POLL_INTERVAL="1"
Plasma Login Manager (KDE Plasma)
# Configuration
GUI_LOGIN_USER="${GUI_LOGIN_USER:-user}"
AUTOLOGIN_CONFIG_DIR="/etc/plasmalogin.conf.d"
AUTOLOGIN_CONFIG_FILE="$AUTOLOGIN_CONFIG_DIR/autologin-autogenerated.conf"
SESSION="plasma.desktop"
DESKTOP_PROCESS="plasmashell"
CONFIG_FILE_TEMPLATE="[Autologin]
User=$GUI_LOGIN_USER
Session=$SESSION"
WAIT_TIMEOUT="60"
GRACE_PERIOD="2"
POLL_INTERVAL="1"
GDM (GNOME)
# Configuration
GUI_LOGIN_USER="${GUI_LOGIN_USER:-user}"
AUTOLOGIN_CONFIG_DIR="/etc/gdm3/conf.d"   # Debian/Ubuntu
AUTOLOGIN_CONFIG_FILE="$AUTOLOGIN_CONFIG_DIR/90-autologin-autogenerated.conf"
SESSION="gnome"
DESKTOP_PROCESS="gnome-shell"
CONFIG_FILE_TEMPLATE="[daemon]
AutomaticLoginEnable=true
AutomaticLogin=$GUI_LOGIN_USER"
WAIT_TIMEOUT="60"
GRACE_PERIOD="2"
POLL_INTERVAL="1"

Caveats:

  • Fedora and some other distros ship GDM without conf.d fragment support. On those systems autologin must be set by editing /etc/gdm/custom.conf in place.
  • Because custom.conf is a shared file rather than a fragment, the "write a new file, then delete it" cleanup pattern does not translate directly. Save the original lines and restore them instead.
  • Confirm that the fragment directory is actually read by your GDM version. Some versions require a specific include directive in the main configuration.
LightDM (XFCE, LXDE, MATE, Cinnamon)
# Configuration
GUI_LOGIN_USER="${GUI_LOGIN_USER:-user}"
AUTOLOGIN_CONFIG_DIR="/etc/lightdm/lightdm.conf.d"
AUTOLOGIN_CONFIG_FILE="$AUTOLOGIN_CONFIG_DIR/50-autologin-autogenerated.conf"
SESSION="xfce"   # or lxde, mate, cinnamon
DESKTOP_PROCESS="xfce4-session"   # or lxsession, mate-session, cinnamon-session
CONFIG_FILE_TEMPLATE="[Seat:*]
autologin-user=$GUI_LOGIN_USER
autologin-session=$SESSION"
WAIT_TIMEOUT="60"
GRACE_PERIOD="2"
POLL_INTERVAL="1"

SESSION must match a valid .desktop file name (without the extension) in /usr/share/xsessions.

Init system support

The script currently supports systemd only and assumes there is a symlink pointing display-manager.service to the current display manager service file, though it can be easily adapted to other systems by editing the systemctl restart display-manager.service line with the command to restart the display manager.

About

Simple Shell script that takes advantage of display manager's autologin feature to log a user into a graphical session without having physical access to the machine.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages