DEV Community

vinayak
vinayak

Posted on • Originally published at thebackendblog.com on

How to Show Asterisks While Typing Sudo Password in Linux

Terminal

When using the sudo command in Linux, it is common to be prompted for the user's password. However, by default, the password is not displayed on the screen while typing. This can be a security feature, but it can also be inconvenient if the user needs to verify what they are typing.

But we can enable asterisks to show while typing the sudo password, follow simple steps:

  • Open the terminal and type the following command:
sudo visudo
Enter fullscreen mode Exit fullscreen mode

sudo visudo is a command in Linux that allows a user with administrative privileges to edit the sudoers file, which contains the rules for the sudo command. This file determines which users are allowed to run sudo and what commands or actions they are allowed to execute with it. The visudo command ensures that the file is edited safely and consistently, and checks for syntax errors before saving the file.

  • Enter your password when prompted. Note that the password will not be displayed on the screen. This will open the sudoers file in the terminal.

Terminal

  • Look for the line that contains the following text:
 Defaults env_reset
Enter fullscreen mode Exit fullscreen mode
  • Add the following text after it:
 Defaults pwfeedback
Enter fullscreen mode Exit fullscreen mode

Terminal

  • Save and exit the file, by pressing Ctrl+X , then Y , and then Enter if you are using nano else :wq if using vim/nvim

  • Now, when the user types sudo in the terminal and is prompted for their password, asterisks will appear on the screen as they type.

Terminal

It is worth noting that this feature may not be available in all versions of Linux or in all terminals. Additionally, displaying the password as it is typed can be a security risk if other people are present who should not see the password. Therefore, use this feature with caution and only when necessary.

Top comments (3)

Collapse
 
josephj11 profile image
Joe

I just installed doas, a sudo replacement because I heard that sudo is insecure. I haven't converted everything to use it yet.

Collapse
 
itsvinayak profile image
vinayak

Hi @josephj11 ,

Thanks for sharing, now i am excited to give it a try

Collapse
 
rendick profile image
rendick

Thanks, helpful guide

Image description