linux可將使用者從群組中刪除嗎
可以。刪除方法:1、使用usermod從群組中刪除用戶,語法「sudo usermod -G root 用戶名」;2、使用gpasswd從指定群組中刪除用戶,語法「sudo gpasswd -d 用戶名群組名稱」;3、編輯“/etc/group”文件,手動從群組中刪除使用者。
本教學操作環境:linux7.3系統、Dell G3電腦。
在Linux中,使用者可以是一個主要群組和一個或幾個次要(輔助)群組的成員。檔案「 / etc / group」為Linux系統中的每個使用者定義了群組成員身分。
在本教學中,我們將學習如何在Linux群組中刪除使用者。我們將使用兩種方法,還將展示如何透過從「 / etc / group」檔案中刪除來手動從群組中刪除使用者。
建立Linux使用者
就本教學而言,我們將建立一個名為「 testuser」的使用者。當建立一個新使用者時,也會建立一個與該使用者同名的新主要群組。
我們將透過發出以下命令來建立新使用者:
$ sudo useradd -m testuser
#現在,我們可以為該使用者建立密碼:
$ sudo passwd testuser Changing password for user testuser. New password: BAD PASSWORD: The password contains the user name in some form Retype new password: passwd: all authentication tokens updated successfully.
我使用了與使用者名稱相同的密碼,因此我收到警告,密碼中不應包含使用者名稱的某種形式。
將使用者新增至群組
首先,我們將使用groupadd指令建立兩個新群組,指令如下所示:
$ sudo groupadd testgroup1$ sudo groupadd testgroup2
現在,我們將「 testuser」使用者加入到上面建立的兩個群組中,並使用以下命令將「 testuser」使用者新增至「 root」群組:
$ sudo usermod -a -G root testuser $ sudo usermod -a -G testgroup1 testuser $ sudo usermod -a -G testgroup2 testuser
好的,現在來看看「 / etc / group」文件,可以看到「 testuser」是這三個群組的成員。
$ cat /etc/grouproot:x:0:testuser.............testuser:x:1001:testgroup1:x:1002:testusertestgroup2:x:1003:testuser
找出使用者所屬的群組
#我們也可以使用以下兩種替代方法來檢查使用者屬於哪個群組
$ groups testuser testuser : testuser testgroup1 testgroup2 root$ id -nG testuser testuser testgroup1 testgroup2 root
可以看到輸出非常相似,而這些指令完成的是相同的事情。
使用usermod從群組中刪除使用者
我們可以使用usermod指令一次從一個或多個群組中刪除一個使用者。使用usermod時,您必須指定將使用者保留在哪些輔助群組中。讓我用一個範例來解釋一下。
$ groups testuser testuser : testuser testgroup1 testgroup2 root
為了從“ testgroup1”和“ testgroup2”群組中刪除使用者“ testuser”,請執行下列命令(即,僅將testuser保留在“ root”群組中,它是主要的「 testuser」群組):
$ sudo usermod -G root testuser
Results$ groups testuser testuser : testuser root
因此,為了將使用者分割為更多的群組,您需要提及以逗號(,)分隔的組名,例如:
$ sudo usermod -G root,testgroup1 testuser
Results# groups testusertestuser : testuser root testgroup1
#使用gpasswd從群組中刪除使用者
完成類似結果的另一個指令是gpasswd。與usermod不同,我們使用此命令從指定的群組中刪除使用者。
要從一個特定的群組中刪除用戶,我們可以使用gpasswd命令:
$ sudo gpasswd -d testuser root Removing user testuser from group root $ groups testuser testuser : testuser testgroup1 testgroup2 $ sudo gpasswd -d testuser testgroup1 Removing user testuser from group testgroup1 $ groups testuser testuser : testuser testgroup2
從群組中刪除用戶(手動)
我們也可以透過手動編輯檔案'/ etc / group'從群組中刪除使用者。重新啟動後,此方法的效果將應用於使用者。
你可以使用最喜歡的文字編輯器來編輯「 / etc / group」檔案:
$ cat /etc/group .............sssd:x:993:sshd:x:74:chrony:x:992:vagrant:x:1000:slocate:x:21:vboxsf:x:991:testuser:x:1001:testgroup1:x:1002:testusertestgroup2:x:1003:testuser$ groups testuser testuser : testuser testgroup1 testgroup2 root
現在,我們將手動編輯最後兩個條目來刪除testuser,並從testgroup1和testgroup2中刪除(編輯後的檔案應如下所示):
$ cat /etc/group............. sssd:x:993: sshd:x:74: chrony:x:992: vagrant:x:1000: slocate:x:21: vboxsf:x:991: testuser:x:1001: testgroup1:x:1002: testgroup2:x:1003:
變更將在重新啟動後進行,現在該使用者已從這兩個群組中刪除:
$ groups testuser testuser : testuser root
結論
在本教學中,我們學習如何使用usermod、gpasswd以及從「 / etc / group」檔案手動刪除使用者來從群組中刪除使用者。
相關推薦:《Linux影片教學》
以上是linux可將使用者從群組中刪除嗎的詳細內容。更多資訊請關注PHP中文網其他相關文章!

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

Linux系統的五個基本組件是:1.內核,2.系統庫,3.系統實用程序,4.圖形用戶界面,5.應用程序。內核管理硬件資源,系統庫提供預編譯函數,系統實用程序用於系統管理,GUI提供可視化交互,應用程序利用這些組件實現功能。

VS Code 一步/下一步快捷鍵的使用方法:一步(向後):Windows/Linux:Ctrl ←;macOS:Cmd ←下一步(向前):Windows/Linux:Ctrl →;macOS:Cmd →

要查看 Git 倉庫地址,請執行以下步驟:1. 打開命令行並導航到倉庫目錄;2. 運行 "git remote -v" 命令;3. 查看輸出中的倉庫名稱及其相應的地址。

雖然 Notepad 無法直接運行 Java 代碼,但可以通過借助其他工具實現:使用命令行編譯器 (javac) 編譯代碼,生成字節碼文件 (filename.class)。使用 Java 解釋器 (java) 解釋字節碼,執行代碼並輸出結果。

在 Sublime 中運行代碼的方法有六種:通過熱鍵、菜單、構建系統、命令行、設置默認構建系統和自定義構建命令,並可通過右鍵單擊項目/文件運行單個文件/項目,構建系統可用性取決於 Sublime Text 的安裝情況。

Linux的主要用途包括:1.服務器操作系統,2.嵌入式系統,3.桌面操作系統,4.開發和測試環境。 Linux在這些領域表現出色,提供了穩定性、安全性和高效的開發工具。

要安裝 Laravel,需依序進行以下步驟:安裝 Composer(適用於 macOS/Linux 和 Windows)安裝 Laravel 安裝器創建新項目啟動服務訪問應用程序(網址:http://127.0.0.1:8000)設置數據庫連接(如果需要)
