4

I'm using a Linux (RHEL6) workstation. I have a small script I wrote which locks and unlocks the screen via xscreensaver when I connect or disconnect my USB thumb drive, which effectively turns it into a physical key to my workstation. The problem is that there doesn't seem to be a good way to unlock xscreensaver from the command line. xscreensaver-command -deactivate, counterintuitively, only "simulates user activity" and still requires a password to unlock the screen. xscreensaver-command -exit only kills the parent daemon xscreensaver if there is not a screensaver running. As the man page for xscreensaver-command -exit warns,

Warning: never use kill -9 with xscreensaver while the screensaver is active.  If you are using a virtual root window  manager,
that can leave things in an inconsistent state, and you may need to restart your window manager to repair the damage.

Indeed, I am currently using pkill xscreensaver as my method to get rid of the screensaver from a script, which often results in zombie processes and other messes. How can I unlock the screensaver safely from a script/the command line?

2 Answers2

3

Given xscreensaver's near-monomaniacal focus on security, as hinted at by the answers in jwz's xscreensaver FAQ and further elucidated in On Toolkits, I strongly doubt that stock xscreensaver will unlock without a password by any method short of the forcible kill you're currently using. Your best option would likely be to modify the source to include something like a "-forceunlock" option, and build your own binary from that.

Aaron Miller
  • 10,087
2

sudo killall -9 xscreensaver is the answer. If you kill it, the screen unlocks, plain and simple. Then you can re-launch it with DISPLAY=:0 xscreensaver -no-splash and then lock it with DISPLAY=:0 xscreensaver-command -lock. There are security implications in unlocking the screen, of course, but I needed this and I'm aware of what I'm doing. Do this to your own risk, end of the disclaimer.

Avio
  • 957