Skip to content

Instantly share code, notes, and snippets.

@Deali-Axy
Created October 1, 2025 14:30
Show Gist options
  • Select an option

  • Save Deali-Axy/409d3d22099a6547f92f761a8cfeeab4 to your computer and use it in GitHub Desktop.

Select an option

Save Deali-Axy/409d3d22099a6547f92f761a8cfeeab4 to your computer and use it in GitHub Desktop.
一键开启或关闭 sudo 输入密码时的星号显示功能
#!/bin/bash
# 一键配置 sudo 密码输入是否显示星号
# 用法: ./pwfeedback.sh on|off
set -e
CONFIG_FILE="/etc/sudoers.d/0pwfeedback"
if [ "$EUID" -ne 0 ]; then
echo "请使用 root 或 sudo 运行该脚本"
exit 1
fi
case "$1" in
on)
echo "Defaults pwfeedback" > "$CONFIG_FILE"
echo "已开启:sudo 输入密码时会显示星号 (*)"
;;
off)
echo "Defaults !pwfeedback" > "$CONFIG_FILE"
echo "已关闭:sudo 输入密码时不显示星号"
;;
*)
echo "用法: $0 {on|off}"
exit 1
;;
esac
@Deali-Axy
Copy link
Author

开启星号显示

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

关闭星号显示

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment