You can activate your linux screen saver or screen lock by running this command:
gnome-screensaver-command --lock
or
xlock
But if you ssh into your linux machine to activate the screen lock or screen saver, you might run into this error:
** Message: Failed to connect to the D-BUS daemon: dbus-launch failed to autolaunch D-Bus session: Autolaunch error: X11 initialization failed.
or
No protocol specified xscreensaver: Can't open display: :0.0
You have to set the DBUS_SESSION_BUS_ADDRESS environment variable in order the command to work. You can find the current running DBUS address by first getting the process id of the running screen saver. Then grepping for the address in the environ file. The following script will lock your linux terminal:
#!/bin/sh PID=`pgrep -u $USER -f "gnome-screensaver"` DBUS_SESSION_BUS_ADDRESS=`grep -z DBUS_SESSION_BUS_ADDRESS /proc/$PID/environ` DBUS_SESSION_BUS_ADDRESS=`echo $DBUS_SESSION_BUS_ADDRESS | sed -e 's/DBUS_SESSION_BUS_ADDRESS=//'` export DBUS_SESSION_BUS_ADDRESS gnome-screensaver-command --lock
Holy remote locking Batman!