Lock Gnome Screen via SSH

Page content

Overview

I want to lock gnome-session(Desktop) with a user logged in via ssh.

Script

Save below script and execute it.

There are two key points at line 10.

1. gnome-screensaver-command -l

Execute gnome-screensaver-command as GNOME logged in user.

2. DBUS_SESSION_BUS_ADDRESS

Set dbus environment varibale to execute gnome-screensaver-command.

Reference