How to Show Asterisks While Typing Sudo Password in Linux

How to Show Asterisks While Typing Sudo Password in Linux

Table of contents

No heading

No headings in the article.

When using the sudo command in Linux, it is common to be prompted for the user's password. However, the password is not displayed on the screen while typing by default. 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:

  1. Open the terminal and type the following command:

     sudo visudo
    

    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.

  2. 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.

  3. Look for the line that contains the following text:

     Defaults env_reset
    
  4. Add the following text after it:

     Defaults pwfeedback
    

    pwfeedback is a setting in the sudoers file that enables the display of asterisks while typing the sudo password in Linux. This setting must be added to the sudoers file manually to activate the feature.

  5. 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

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

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.

Did you find this article valuable?

Support Vinayak Sharma by becoming a sponsor. Any amount is appreciated!