Displaying Asterisks for Password Input in Linux Terminal

Introduction

Recently, my hard drive failed, and I spent a lot of time recovering and organizing data, resulting in very low productivity. 🤣

My hard drive broke down

The hard drive suddenly failed, and it took me half a month to recover the data… (including data recovery tools)

As for the promised new website, it has also been delayed.

Not much progress has been made on the project, but I have learned a lot about system configuration, and I will write some articles to document it.

Linux Mint system defaults to displaying asterisks, which I find to be a very good experience. Although some people think it is insecure, it doesn’t matter; usability is key.

Configuration

This setting is located in /etc/sudoers.d/0pwfeedback

This file contains just one line

Defaults pwfeedback

If you do not want to display asterisks, just add an exclamation mark.

Defaults !pwfeedback

One-Click Configuration Script

I also wrote a script that can enable or disable the asterisk display feature for sudo password input with one click.

# Enable asterisk display
curl -sSL https://gist.github.com/Deali-Axy/409d3d22099a6547f92f761a8cfeeab4/raw/e684032255024fe085663e29487ac0107abd06c6/pwfeedback.sh | sudo bash -s on

# Disable asterisk display
curl -sSL https://gist.github.com/Deali-Axy/409d3d22099a6547f92f761a8cfeeab4/raw/e684032255024fe085663e29487ac0107abd06c6/pwfeedback.sh | sudo bash -s off

Below is the source code of the script

Save it as <span>pwfeedback.sh</span> and grant executable permissions:

chmod +x pwfeedback.sh

The script content is as follows:

#!/bin/bash
# One-click configuration for whether to display asterisks for sudo password input
# Usage: ./pwfeedback.sh on|off

set -e

CONFIG_FILE="/etc/sudoers.d/0pwfeedback"

if [ "$EUID" -ne 0 ]; then
  echo "Please run this script as root or with sudo"
  exit 1
fi

case "$1" in
  on)
    echo "Defaults pwfeedback" > "$CONFIG_FILE"
    echo "Enabled: Asterisks (*) will be displayed when entering the sudo password"
    ;;
  off)
    echo "Defaults !pwfeedback" > "$CONFIG_FILE"
    echo "Disabled: Asterisks will not be displayed when entering the sudo password"
    ;;
  *)
    echo "Usage: $0 {on|off}"
    exit 1
    ;;
esac

Now you can switch using the following commands:

# Enable asterisk display
sudo ./pwfeedback.sh on
# Disable asterisk display
sudo ./pwfeedback.sh off

References

  • https://www.zhihu.com/question/580286026/answer/3343182381

Unlocking AI-Driven Productivity Leap

Programming Design Laboratory focuses on the implementation of cutting-edge technologies, analyzing code-level solutions weekly.

Follow to get:

🔹 “DeepSeek Quick Start Manual” 24 pages of content: Master intelligent coding in 3 days from scratch

🔸 Exclusive Tsinghua course trilogy:

  • ❶ “DeepSeek from Beginner to Expert” 104 pages of detailed explanation (including 30+ code examples)
  • ❷ “Workplace Efficiency Revolution Guide” 35 pages of practical: In-depth analysis of 7 major industry application scenarios
  • ❸ “AI Dividend Capture Manual” 65 pages of secrets: 5 paths for ordinary people to quickly build competitive barriers

Building a new paradigm of intelligent development with thousands of technical professionals.

Leave a Comment