How to change language automatically when prompted for a password?

Martin Smith

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?

sudodus

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:

  1. The shebang tells that bash should be used to run the shellscript.
  2. The original keyboard setting is saved.
  3. The keyboard is changed to US English.
  4. sudo is started, and if not run recently, it will ask for password.
  5. The keyboard is reset to the original setting.
  6. The previous 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.

edited at
0

Comments

0 comments
Login to comment

Related

How to automatically enter username and password when prompted to connect to a remote server

How to automatically enter user password when prompted by terminal

How to provide input to cmd automatically when prompted?

Repeatedly prompted to change password on every ssh login

How to change my windows password automatically?

The language changes automatically when I change the night mode

Prompted for key password when key is in ssh-agent

Amazon EC2 - Prompted for Password when Switching to Passwordless User

Automatically do keypress enter when prompted in command prompt

MySQL prompted twice for password

how to create a guest account without disk encryption password prompted

How to change password visibility when clicking outside of a password field

How to change/disable password complexity test when changing password?

How to change language of app when user selects language?

How to change the language of the app when THE USER selects the language?

Notepad++: How to automatically set Language as Xml when load files

Yeoman generator - How to change the content of some file depending on a prompted param

How to make python script press 'enter' when prompted on Shell

How to make python script type when prompted on shell

how to declare that you have full superuser permissions when prompted on terminal?

How to display a message when a prompted input isn't entered?

Why am I being prompted for a sudo password when I specified "NOPASSWD" in my /etc/sudoers file?

Why am I prompted for a password when using SSH to connect to another server?

Not prompted to input the root password when installing mariadb-server on Ubuntu 16.04 LTS

Change the language of the home/user/ folders automatically

How automatically change to different program when a button is pressed in Python

How to create an alert when cells automatically change value?

How to automatically change volume level when un-/plugging headphones?

Mongodb server. How to automatically change the status is expired when expired