在 Debian(及大多数 Linux 发行版)里,deluser 确实有一定误删风险,但风险大小和具体用法有关。下面分情况说明。
deluser 本身的行为deluser 是 Debian 下用于删除用户或组的工具,常见用法:
deluser 用户名
deluser --remove-home 用户名
deluser --group 组名
deluser alice
/etc/passwd、/etc/shadow 中的用户deluser --remove-home alice
/home/alicedeluser --remove-all-files alice
deluser roo t
(手滑)
→ 直接删除真实用户,可能造成系统不可用
Debian 有很多系统用户,如:
www-datamysqlpostgresnobodydeluser www-data
→ 网站、数据库直接挂掉
--remove-all-filesdeluser --remove-all-files tom
→ 如果 tom 曾拥有 /var/www、/data 等目录
→ 直接数据灾难
删除用户后:
→ 权限混乱,难以排查
id 用户名
grep 用户名 /etc/passwd
usermod -L 用户名
或
chsh -s /usr/sbin/nologin 用户名
tar czf alice_home.tar.gz /home/alice
--remove-all-files除非你非常清楚文件归属
awk -F: '$3 < 1000 {print $1}' /etc/passwd
deluser有风险,但可控
--remove-all-files:高风险如果你愿意,可以告诉我:
我可以给你一条最安全的删除命令。