Sunday, May 5, 2024
96
rated 0 times [  96] [ 0]  / answers: 1 / hits: 160700  / 1 Year ago, fri, february 3, 2023, 7:39:20

I am using Ubuntu 12.04. Is there any way to lock the screen or session from a terminal command or script?


More From » command-line

 Answers
2

Simple:



gnome-screensaver-command -l


The following can also work, if the screensaver is set to lock when activate (see screensaver settings), since the command activates the screensaver:



gnome-screensaver-command -a


You can add an alias to the command by editing the file .bashrc (or .bash_aliases) in your home directory:



gedit $HOME/.bashrc


and adding the following line:



alias lock='gnome-screensaver-command -l'


Then from terminal:



source .profile


This will activate the alias.
From now on, the alias lock in a terminal will have the effect of locking the screen.


[#35719] Friday, February 3, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ameatoes

Total Points: 321
Total Questions: 106
Total Answers: 112

Location: Belarus
Member since Sat, Jul 18, 2020
4 Years ago
ameatoes questions
Tue, Aug 16, 22, 22:50, 2 Years ago
Fri, May 14, 21, 03:36, 3 Years ago
Sat, Oct 8, 22, 01:00, 2 Years ago
Fri, Feb 17, 23, 14:44, 1 Year ago
;