3

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?

jayhendren
  • 500
  • 3
  • 13
  • Given [the philosophy underlying its design](http://www.jwz.org/xscreensaver/faq.html), 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 Jul 08 '13 at 17:39
  • Thank you Aaron. I don't see how your link is relevant, but I trust that you're correct. If this were an answer, I would accept it, though it is not what I want to hear. – jayhendren Jul 08 '13 at 18:17
  • Comment converted to answer, and expanded to give greater background. Glad to be of help! (And, hey, it probably won't be all that hard to modify the source -- inasmuch as I'm competent to pass any kind of judgment on jwz's code, I have found it extremely well-written and easy to work with.) – Aaron Miller Jul 08 '13 at 18:42

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
  • 9,782
  • 24
  • 39
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
  • 908
  • 1
  • 13
  • 18
  • 1
    Downvoting because the question already addresses `kill -9` and this answer doesn't add any new information. – jayhendren Apr 05 '19 at 16:22
  • You are of course free to downvote, but my answer describes one of the possible "correct" ways of doing what the OP is asking (and it also solved my problem brilliantly btw). Uh, it also adds the new important information on how to lock the screen again from command line. – Avio Apr 09 '19 at 12:57