I am using Ubuntu 12.04. Is there any way to lock the screen or session from a terminal command or script?
|
Simple:
The following can also work, if the screensaver is set to lock when activate (see screensaver settings), since the command activates the screensaver:
You can add an alias to the command by editing the file .profile in your home directory:
and adding the following line:
Then from terminal:
This will activate the alias.
From now on, the alias |
|||||||||||||||||||||
|
|
In addition to what January said, this also works:
or
According to the
For further clarification, here is another question/answer (also by January) which describes the differences between invoking the lock and activating your screensaver: Difference between gnome-screensaver-command -a and gnome-screensaver-command -l |
||||
|
|
|
Please install vlock. Then you can switch to a VT (text terminal, using Ctrl+Alt+F1) and run
This works whether you have X11 running or not. |
|||||||||||||
|
|
In case that you need to lock the screen on a terminal in a non-GUI environment you could make use of screen While in Ctrl + a Ctrl + x |
|||||||||
|
|
Starting in Ubuntu 14.04, Unity's lock screen no longer uses gnome-screensaver. The command If that command does not work (say, for instance, that gnome-screensaver is not installed), bringing up the proper Unity lock screen (not the greeter where you can switch users) can be done via this command in a terminal:
|
||||
|
|
this starts the screen saver in locked mode and then puts your display in standby. sweet and simple, no sudo. command line or shell script works fine. i use this for a keyboard hotkey. Ubuntu Mate 15.10 |
|||||||||
|
|
For LightDM users, try |
|||||||||||||
|
|
A dirty hack of using the shortcut Ctrl+Alt+L for the locking the screen from a terminal:
Refer to the manual page for xdotool for more. |
|||||
|
|
It depends on your display manager.
I have lightdm, I can do |
||||
|
|
|
A similar situation to lock the screen in lubuntu in lubuntu 17.10 (not ubuntu) this works |
|||
|
|
|
In my case |
||||
|
|