4

I have a computer with large hard drives configured with encrypted home. It so happens, that the same computer also works my family's main kodi media center. Each time my kids want to see a movie, I have to turn it on, and then physically connect a keyboard to it, and type in the password.

I would love to be able to do that remotely.

Of course I also have a root access to the computer.

I am not willing to create another username with automatic login, because most of the media files are encrypted and I want them to stay this way.

The normal combination of export DISPLAY=0: and source discover_session_bus_addres.sh and xdotool type my_secret_password that works for typing into the lock screen doesn't work on the lightm.

2
  • Which user did you run the commands as? LightDM's X session is probably run under the lightdm user
    – muru
    Mar 29, 2018 at 6:19
  • @muru On Ubuntu 16.04 it is root. Mar 29, 2018 at 7:02

3 Answers 3

5

Here is an answer that works under Ubuntu 16.04 with lightdm:

  1. Make yourself root to get access to the lightdm's .Xauthority, which is located under /var/lib/lightdm/.Xauthority. Either copy it somewhere where it will be readable by you and drop your root permissions, or simply remain root.
  2. set XAUTHORITY to point to that file (e.g. export XAUTHORITY=/var/lib/lightdm/.Xauthority)
  3. set DISPLAY to the active display (export DISPLAY=:0)
  4. xdotool should work now. Try

    xdotool type "My super secret password"  
    xdotool key Return
    
1

Here is the workaround that I'm using. It is ugly and rude, but this approach shall work also within Wayland and GDM (Ubuntu 17.10) if the auto login option works at all.

#!/bin/bash

# NAME: lightdm-auto-login

main() {
    # If the file '/etc/lightdm/lightdm.conf' exists create a backup copy
    [[ -f /etc/lightdm/lightdm.conf ]] && mv /etc/lightdm/lightdm.conf{,.bak}

    # Create autologin configuration for the current $USER = $1
    echo -e "[Seat:*]\nautologin-user=$1" > /etc/lightdm/lightdm.conf

    # Restart 'lightdm' while autologin option is enabled
    systemctl restart lightdm.service

    # Wait for a moment to complete the login process and remove the conf file
    sleep 30 && rm /etc/lightdm/lightdm.conf

    # Restore the backup if exists
    [[ -f /etc/lightdm/lightdm.conf.bak ]] && mv /etc/lightdm/lightdm.conf{.bak,}
}

# Execute the 'main()' function with root privileges in the background 'sudo -b'
# Pass the curent $USER as arg (https://unix.stackexchange.com/a/269080/201297)
sudo -b bash -c "$(declare -f main); main $USER"
  • The script should be executed as regular user (that belongs to the sudoers group).

  • The script will create a backup copy of the file /etc/lightdm/lightdm.conf. Then it will generate a new configuration file with auto login option, enabled for the current user. At this point the lightdm will be restarted and the user will be login by the auto login option. Finally the custom configuration will be removed and the original state of the configuration file will be restored.

  • If GDM in use: the service to be restarted is gdm3.service and the configuration file that should be changed is /etc/gdm3/custom.conf.

0

This works fine for me (from ssh, with lightdm):

$ XAUTHORITY=/var/lib/lightdm/.Xauthority DISPLAY=:0.0 sudo sh -c 'xdotool type "My Password" && xdotool key Return'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .