Remote Lock Screen and Remote Unlock Screen on Linux (Ubuntu)

On Jan 7, 2010 9 comments

After my several post about Lock Screen on Linux (Ubuntu) from Command Line, Lock Screen on Linux (Ubuntu) from First Boot, and Run or Execute Multiple Command on SSH, now I will continue with Remote Lock Screen and Remote Unlock Screen on Linux (Ubuntu).

Sometimes we need to lock a computer from different location to keep it save from abuse. But we need to lock the remote computer's screen just in one command.

To do this you need openssh-server installed on your remote computer and ssh-client installed on your computer. If you using Ubuntu, you will have this ssh-client on you Ubuntu default install.


In this post I am using ubuntu both on remote computer and my computer. To lock the screen simply type this command on terminal :

$ ssh -X user@server "export DISPLAY=:0; gnome-screensaver; gnome-screensaver-command -l;"

You may use that command without "-X" option if you have X forwarding enabled (ForwardX11 yes) on your ssh configuration. But you need to remember with "export DISPLAY=:0", without this the command will give the lock screen on your computer, not your remote computer.

To unlock the screen on your remote computer, type this command on your computer :

$ ssh -X user@server "export DISPLAY=:0; gnome-screensaver; gnome-screensaver-command -d;"

Now, with this two command you can lock and unlock your remote computer with just one ssh command.

9 comments:

Ibrahim kasem said...

Can I shutdown or restart a remote computer using ssh ?
regards

zulian said...

Yes you can.
See my post about Remote Shutdown and Remote Reboot on Linux (Ubuntu) with Just One SSH Command

Unknown said...

Works a treat! Thank you :)

zulian said...

you're welcome

fukawi2 said...

Awesome. I love Linux. Do that on Windows :P

David J. Biesack said...
This comment has been removed by the author.
David J. Biesack said...

Thanks for posting this. Note that installing xscreensaver (Jamie Zawinski) may make gnome-screensaver-command a symlink to xscreensaver-command which does not recognize -d ; you must use

gnome-screensaver-command -deactivate

or more directly

xscreensaver-command -deactivate

manac said...

Hello!
Is it possible to log in to computer with some script instead of typing the password at the login screen? I'm trying to make login via facial recognition and I'm able to do the recognition but I don't know how to make the login when the facial recognition succeeds. Could you help me about this?
Thank you in advance!

Unknown said...

on ubuntu 14.04 (both computers) I get:
** (gnome-screensaver:9737): WARNING **: Couldn't get presence status: The name org.gnome.SessionManager was not provided by any .service files

Post a Comment