deluser
是一個用于刪除用戶賬戶及其相關文件的命令行工具。在 Ubuntu 系統中,正確使用 deluser
的基本語法如下:
sudo deluser [選項] 用戶名
以下是一些常用的選項:
-r
或 --remove-home
:刪除用戶的主目錄及其內容。-f
或 --force
:強制刪除用戶,即使該用戶正在運行某些進程。-z
或 --remove-all-files
:刪除用戶的所有文件,包括系統文件。-D
或 --delete-home
:刪除用戶的主目錄及其內容,類似于 -r
選項。-s
或 --shell SHELL
:指定一個新的默認 shell,用于替換被刪除用戶的當前 shell。以下是一些示例:
username
及其主目錄:sudo deluser username
username
及其主目錄和所有文件:sudo deluser --remove-home --remove-all-files username
username
并將其默認 shell 更改為 /bin/false
:sudo deluser --shell /bin/false username
在使用 deluser
之前,請確保您已備份所有重要數據,因為此操作無法撤銷。