返回文章列表文章索引阅读全文
STARBLOG / 阅读手记
系统配置

Display asterisks when entering password in Linux terminal

Linux default password asterisks? That's actually a nice touch. One line of sudoers configuration does the trick, yet some people really do resort to scripts for this. Turning it off? That's just shooting yourself in the foot.

曦远 (DealiAxy)约 6 分钟
目录7 个章节

Preface

By default, the LinuxMint system displays asterisks during password input, which many users find to be a very good experience. While some people may consider this less secure, that's not a big deal—functionality is what really matters.

Configuration

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

This file contains a single line:

Defaults pwfeedback

If you don't 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 passwords with a single click.

# Enable Asterisk Display (开启星号显示)
```bash
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 script source code.

Save as `pwfeedback.sh` and make it executable:

```bash
chmod +x pwfeedback.sh

The script content is as follows:

#!/bin/bash

Toggle Asterisk Display 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: sudo will display asterisks (*) when entering the password" ;; off) echo "Defaults !pwfeedback" > "$CONFIG_FILE" echo "Disabled: sudo will not display asterisks when entering the password" ;; *) echo "Usage: $0 {on|off}" exit 1 ;; esac


You can use the following command to toggle it:

```bash
# Enable Asterisk Display
sudo ./pwfeedback.sh on
# Disable asterisk display
sudo ./pwfeedback.sh off

References

_EOF_

Display asterisks when entering password in Linux terminal

本文作者:
程序设计实验室
版权声明:
本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!

相关文章

Linux设置系统邮件转发到指定邮箱

前言 在Linux的操作中,有的时候每敲一下回车,就出来You have new mail in /var/spool/mail/root的提示,究竟是为什么呢? Linux 系统经常会自动发出一些邮件来提醒用户系统中出了哪些问题(收件箱位置:/var/mail/)。可是这些邮件都是发送给 root 用户的。出于系统安全考虑,通常不建议大家直接使用 root 帐户进行日常操作。所以要想点办法来让系

2025-10-27 · 系统配置 · 约 1 分钟

讨论

共 0 条

良言一句三冬暖,恶语伤人六月寒。

加载评论中…