deluser
命令在 CentOS 系統中用于刪除用戶賬戶
deluser
命令的基本語法如下:
deluser [選項] 用戶名 [用戶組]
其中,選項
可以是以下之一:
-f
或 --force
:強制刪除用戶,即使該用戶有登錄會話或正在運行進程。-r
或 --remove
:刪除用戶的主目錄及其內容。-s
或 --shell
:將用戶的默認 shell 更改為 /sbin/nologin
,以防止用戶登錄。用戶名
是要刪除的用戶賬戶的名稱。
用戶組
(可選)是要刪除的用戶所屬的主要用戶組。如果不指定此選項,系統將刪除用戶及其主要用戶組。
以下是一些使用 deluser
命令的示例:
exampleuser
的用戶,并將其主要用戶組設置為 examplegroup
:deluser exampleuser examplegroup
exampleuser
的用戶,即使該用戶有登錄會話:deluser -f exampleuser
exampleuser
的用戶,并刪除其主目錄及其內容:deluser -r exampleuser
exampleuser
的用戶的默認 shell 更改為 /sbin/nologin
:deluser -s /sbin/nologin exampleuser
請注意,在使用 deluser
命令時要小心,因為刪除用戶賬戶將導致與該用戶相關的所有文件和資源丟失。在執行此操作之前,請確保已備份所有重要數據。