Seeking an "operator present" indication for a remote system accessed over ssh

An elderly relative uses a Ubuntu 18.04 + LXDE desktop, mostly just for internet browsing and to play a few word games. They rarely shut the PC down...last time I checked, it had been turned on for over 15 days.

I administer the system remotely over ssh.

For the occasional time that I need to reboot the system, I'd like some means to determine if my relative is actively using it so that I don't disrupt them. I've done it in the middle of the night sometimes, but they sleep poorly and sometimes get up and play their games then.

Calling them on the phone works, but there are several time zones between us, and sometimes it wakes them up.

If they are playing a game, I can see that in top, but I can't find a way to tell if they are actively using the browser.

Some kind of mouse and/or keyboard activity indicator would be awesome, but I wish to stay away from any kind of keylogger type software. I suspect such a "mouse/keyboard activity detected" thing exists - to put the system to sleep / activate the screensaver** and wake it up if for nothing else - but I can't find it.

** I don't think they actually use a screensaver, that was just an example. I think the power manager just blanks the screen.

Is there a "time since last keyboard/mouse interaction from user" tracked somewhere?

Any solutions need to be do-able over ssh.


Solution 1:

There exists an utility to print the idle time of the X screen:

DISPLAY=":0" xprintidle

It prints the time since last keyboard or mouse input in milliseconds.


Another option would be to pop up a question box:

DISPLAY=":0" zenity --question --text="Organic Marble asks: Are you currently using this computer?" && echo yes

Then if you get no answer within a few minutes, just ctrl-c it out and proceed to reboot.

Solution 2:

If the monitor is configured to save energy, you may check it:

xset -display :0 q

Look at last line:

Monitor is Off

Solution 3:

Well... this is only an idea, but if you login via ssh to the same user that your relative is using, set the DISPLAY environment variable to :1 and run xinput test n where n is the number corresponding to the mouse (you can obtain that number with xinput --list, in my case it's 9), then that command will print a line of text (in form like motion a[0]=338 a[1]=889) whenever the mouse is moved. So you can pipe the output from that command to some script that will record time when it last got any input, thus you will know when the mouse has been last moved (of course this has to run constantly in the background to record actual time of last mouse movement).

Solution 4:

I think the only way you're going to know for absolutely sure is to "spy" on their screen.

  1. Install x11vnc on their computer with sudo apt-get install x11vnc net-tools

  2. (Optional) Create a shell script on their computer to automate the process of starting the server, so you don't have to remember the syntax every time. Note that the -auth parameter may need to be changed; I only have Fedora to test with right now, and Ubuntu might save the auth file in a different location.

#!/bin/sh
sudo x11vnc -auth /var/run/lxdm/lxdm-\:0.auth -display :0 -rfbport 5900 -localhost
  1. Install your favorite VNC viewer application on your computer.

  2. Set up SSH port tunneling for port 5900 on your computer. Assuming you're using OpenSSH, put the following in your .ssh/config file:

Host theirhostname
    LocalForward 5900 localhost:5900

When you want to actually look at their screen:

  1. SSH into their computer as normal.

  2. Run the shell script (or type out that big sudo x11vnc line).*

  3. Start your VNC viewer application, and direct it to connect to localhost.

Voila, you should be able to see their screen.

*Note: You're going to get several warnings that the VNC server isn't protected by a password. This isn't a security risk, since the VNC server port can only be accessed locally, meaning that any attacker would have to already be logged in. If you're really concerned, though, use x11vnc -storepasswd to create a password file, then add -rfbauth /home/user/.vnc/passwd to the x11vnc command line.