Send message to user logged in to an X11 session at a remote host

There are occasions when you want to contact a user working at a remote computer, but his/her phone is switched off. If the remote user is running an X11 session, and you have ssh access to the remote computer, and you have root privileges on the remote computer, here is a solution.

ssh you@remotehost
sudo DISPLAY=:0 XAUTHORITY=~remoteuser/.Xauthority xmessage "Are you there? Call me. You"

There are alternatives to xmessage if you want more sophistication, for example notify-send, zenity or kdialog.

If you don’t know the correct values for DISPLAY and XAUTHORITY, do the following:

ps -u remoteuser
 2319 ?        00:01:02 xfce4-panel
 2321 ?        00:00:00 Thunar
 2323 ?        00:00:07 xfdesktop
 2329 ?        00:00:31 indicator-cpufr
 2331 ?        00:00:07 indicator-powerpulseaudio
 2343 ?        00:00:21 pulseaudio
 2344 ?        00:00:00 xfce4-volumed
 2350 ?        00:00:02 nm-applet

Pick a process the remote user is running making sure that there is only a single instance of the process, e.g. nm-applet. Then run the following command.

sudo cat /proc/$(echo $(ps -C nm-applet -o pid=))/environ | xargs --null --max-args=1 | egrep '^(DISPLAY|XAUTHORITY)='



Leave a Reply

Your email address will not be published. Required fields are marked *