Show Asterisks While Typing Your Password in the Terminal

Whenever you enter your password in the Terminal whether to install a software or to access a remote server via SSH, you have to type your password. Now, the problem is, that sometimes while typing the password you forget how many characters you’ve entered, and you may have to write the password all over again after clearing the screen.

This is why most applications show visual feedback (asterisk) while entering the password. Linux does not do this because of security reasons, in case someone will know the number of characters of your password. For example, let’s take a look at this installation process of telegram-desktop, if I enter the command and password, the Terminal will show me this :

Password Is Hidden While Installing Telegram
Password Is Hidden While Installing Telegram

In this article, I will show you how to enable that feedback mechanism in Linux.

Backup your sudoers file

We are going to modify a file named sudoers which is located in /etc directory. So let’s create a backup of this in case we mess something up. To do that, open a Terminal and type the following command :

sudo cp /etc/sudoers /etc/sudoers.bak

Modify your sudoers file

After backing up the file, give yourself permission to read and write so that we can modify the file by typing the following command:

sudo chmod +rw /etc/sudoers
Change Permissions For Sudoers File
Change Permissions For Sudoers File

Once executed, open the file in your preferred text editor app (Vim or nano). I’m using vim for demonstration purposes.

# For vim users
sudo vim /etc/sudoers

# For nano Users
sudo nano /etc/sudoers

Look for a line that says :

Defaults env_reset

And now, modify the line so that it looks something like this (press ‘i’ to get into the Insert mode in the vim text editor):

Defaults env_reset,pwfeedback
Add Pwfeedback To Display Asterisks In The Terminal
Add Pwfeedback To Display Asterisks In The Terminal

Now, if you were using vim then press the Esc key to get out of the insert mode and type :wq to write the file and exit. If you were using Nano editor, then save the file by pressing Ctrl+x and then type ‘y’ and press enter to close it.

Finally, you can reload the terminal by typing ‘reset’, and Now you can see feedback whenever you enter your password in the terminal. Let’s try installing Telegram again :

Asterisks Are Now Displayed When You Type The Password
Asterisks are now Displayed When You Type The Password

Summary

You should avoid using this trick anywhere on public computers as it poses a security risk. But for the beginners who get confused by not seeing their password typed out in the terminal, this trick is really helpful. And in my opinion, this setting should be the default in any ‘Beginner Friendly’ distribution.

References

Sudoers Official manual