I have 2 languages (English and Lithuanian) on my system, and my password contains numbers for which I use the dedicated number row (above the letters) on my keyboard. It happens that the Lithuanian language keyboard uses that number row for special letters. So when prompted for a password I usually make a mistake, because the language is set to Lithuanian. How can I automatically change the language to English when prompted for a password?
After a dialogue with Gunnar Hjalmarsson in the comment field I think the following shellscript should work in order to run programs with elevated permissions. It will use US English keyboard when you type the password, and reset the keyboard to your own keyboard directly after that.
You can use the name mysudo
or if you wish a shorter (but unique) program name.
#!/bin/bash
curkeyb=$(setxkbmap -query|grep 'layout:'|sed 's/.* //')
setxkbmap us
sudo echo "sudo $@"
setxkbmap "$curkeyb"
sudo "$@"
Make it executable and copy it to a directory in PATH
, for example
chmod +x mysudo
mv mysudo /usr/local/sbin
and then you can use it instead of sudo
Examples:
mysudo nano hello.txt
mysudo -H gedit hello.txt # remember -H with GUI programs
mysudo parted -ls
Explanation:
bash
should be used to run the shellscript.sudo
is started, and if not run recently, it will ask for password.sudo
command gave the shell elevated permissions for some minutes. This means that the real command can be run with the original keyboard and elevated permissions without asking for password (again).If you install and run onboard
you will see how the keyboard changes so that the top row of keys will map the numbers 1 2 ... 9 0 when the system is waiting for the password, and then changes back to your lanaguage.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments