On Linux, how to prevent `sudo` <kbd>enter</kbd> to replace asterisks with spaces as in the following?

Before <kbd>enter</kbd>:

```bash
sudo whoami
```
```
[sudo] password for benjamin_loison: ****************
```

After <kbd>enter</kbd>:

```bash
sudo whoami
```
```
[sudo] password for benjamin_loison:
root
```
Feb 11, 1:29pm

The behavior you’re observing—where the password asterisks (********) are replaced with spaces after pressing <kbd>Enter</kbd>—is a visual effect in the terminal and is not related to sudo itself. This is how most terminals handle password input for security and usability reasons: the password is not echoed back, and the asterisks (or lack thereof) are just a visual cue.

Why does this happen?

  • The terminal hides your password input for security.
  • The asterisks (or spaces) are just a placeholder and do not affect the actual password being entered.
  • After pressing <kbd>Enter</kbd>, the terminal clears the line for the next output.

Can you prevent this?

No, this is a standard terminal behavior and cannot be changed for sudo password prompts. The password is still correctly processed, regardless of the visual effect.

Workarounds (if you want to see something else)

  • Use a terminal emulator that handles password input differently (though most behave this way).
  • If you’re scripting or automating, use sudo -S to read the password from stdin, but this is not recommended for interactive use due to security risks.

Example of sudo -S (for scripting only)

bash
echo "mypassword" | sudo -S whoami

Warning: This is insecure for interactive use, as it exposes the password in your command history and process list.


In summary: This is normal terminal behavior and cannot be changed for sudo password prompts. The password is still processed correctly.

Feb 11, 1:29pm

This is a shared conversation and may include unverified content that doesn't reflect Mistral AI's views. Login to resume chatting.