My Four-years-old niece is a curious-kid. She loves “Avatar” film very a lot. At any time when the Avatar film is on, she turned so centered and her eyes are glued to the display screen. However the issue is she typically touches a key within the keyboard or transfer the mouse or click on the mouse button whereas watching the film. Typically, she by chance shut or pause the film by urgent a key within the keyboard. So I used to be searching for a method to lock down each the keyboard and mouse, however not the display screen. Fortunately, I got here throughout an ideal answer in Ubuntu discussion board. If you happen to don’t need your cat or pet strolling in your keyboard or your child messing up with the keyboard and mouse whilst you watching one thing essential on the display screen, I recommend you to strive “xtrlock” utility. It’s a easy, but helpful utility to lock the X show until the consumer enters their password on the keyboard. On this transient tutorial, I’ll present you how one can lock the keyboard and mouse, however not the display screen in Linux. This trick will work on all Linux working programs.
Set up xtrlock
The xtrlock package deal is on the market within the default repositories of most Linux working programs. So, you’ll be able to set up it utilizing your distribution’s package deal supervisor.
On Arch Linux and derivatives, run the next command to put in it.
$ sudo pacman -S xtrlock
$ sudo dnf set up xtrlock
On RHEL, CentOS:
$ sudo yum set up xtrlock
$ sudo zypper set up xtrlock
On Debian, Ubuntu, Linux Mint:
$ sudo apt-get set up xtrlock
Lock the Keyboard and Mouse, however not the Display utilizing xtrlock
As soon as xtrlock put in, create a keyboard shortcut. You want this to lock the keyboard and mouse utilizing the important thing mixture of your alternative.
Create a brand new file referred to as lockkbmouse in /usr/native/bin.
$ sudo vi /usr/native/bin/lockkbmouse
Add the next strains into it.
sleep 1 && xtrlock
Save the file and shut the file.
Make it as executable utilizing the next command:
$ sudo chmod a+x /usr/native/bin/lockkbmouse
Subsequent, we have to create keyboard a shortcut.
In Arch Linux MATE desktop:
Go to System -> Preferences -> -> keyboard Shortcuts.
Click on Add to create a brand new shortcut.
Enter the title to your shortcut and add the next line within the command field, and click on Apply button.
bash -c “sleep 1 && xtrlock”
To assign the shortcut key, simply choose or double click on on it and kind the important thing mixture of your alternative. For instance, I exploit Alt+okay.
To clear the important thing mixture, press BACKSPACE key. When you completed, shut the Keyboard Settings window.
In Ubuntu GNOME DE:
Go to System Settings -> Units -> Keyboard. Click on the + (plus) image on the finish.
Enter the title to your shortcut and add the next line within the command field, and click on Add button.
bash -c “sleep 1 && xtrlock”
Subsequent, assign the shortcut key to the newly created shortcut. To take action, simply choose or double click on on it and click on on “Set shortcut” button.
You’ll now see the next display screen.
Kind the important thing mixture of your alternative. For instance, I exploit Alt+okay.
To clear the important thing mixture, press BACKSPACE key. The shortcut key has been assigned. When you completed, shut the Keyboard Settings window.
Any more, everytime you press the keyboard shortcut key (ALT+okay in our case), the mouse pointer will flip right into a a padlock. Now, the keyboard and mouse have been locked, so you’ll be able to freely watch the flicks or no matter you wish to. Even your child or pet touches some keys on the keyboard or clicks a mouse button, they gained’t work.
Right here is xtrlock in motion.
Do you see the a small lock button? It signifies that the keyboard and mouse have been locked. Even should you transfer the lock button, nothing will occur. The duty within the background will preserve operating till you unlock your display screen and manually shut the operating process.
Unlock keyboard and mouse
To unlock the keyboard and mouse, merely sort your password and hit “Enter”. You’ll not see the password as you sort it. Simply sort the password anyway and hit ENTER key. The mouse and keyboard will begin to work after you entered the right password. If you happen to entered an incorrect password, you’ll hear a bell sound. Press ESC key to clear the wrong password and re-enter the right password once more. To take away one character of typed password, press both BACKSPACE or DELETE keys.
What if I completely get locked out of the display screen?
The xtrlock software might not work on some DEs, for instance GDM. It might completely lock you out of the display screen. Please check it in a digital machine after which strive it in your private or official desktop to confirm if it actually works. I examined this on Arch Linux MATE desktop and Ubuntu 18.04 GNOME desktop. It labored simply nice.
Simply in case, you’re locked out of the display screen completely, change to the TTY (CTRL+ALT+F2) then run:
$ sudo killall xtrlock
Alternatively, you should use the chvt command to modify between TTY and X session.
For instance, to modify to TTY1, run:
$ sudo chvt 1
To modify again to the X session once more, sort:
$ sudo chvt 7
Completely different distros makes use of totally different key mixtures to modify between TTYs. Please refer your distribution’s official web site for extra particulars.
In case of GDM crash, even TTY will not be accessible and the system hangs at reached graphical interface. In such circumstances, you would possibly have to chroot into the system and uninstall xtrlock. You could have been warned!
For extra particulars about xtrlock, refer man pages.
$ man xtrlock
And, that’s all for now. Hope this helps. If you happen to discover our guides helpful, please spend a second to share them in your social, skilled networks and assist OSTechNix.
Thanks for stopping by!
Assist us that will help you:
Have a Good day!!