Ubuntu 添加刪除用戶


Ubuntu 添加刪除用戶

為了能夠創建和刪除用戶,您需要以root身份或具有sudo權限的用戶身份登錄。

可以通過兩種方式在Ubuntu中創建新的用戶帳戶:

  • 從命令行
  • 通過GUI

從命令行添加新用戶

useradd是一個用於添加用戶的最普遍命令(所有發行版都支持),而adduser 是useradd 的友好交互式前端,是用Perl編寫的。

sudo adduser username

	Adding user `username' ...
	Adding new group `username' (1001) ...
	Adding new user `username' (1001) with group `username' ...
	Creating home directory `/home/username' ...
	Copying files from `/etc/skel' ...

命令將向你詢問一系列的問題。密碼是必需的,其他字段都是可選的。

Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully
Changing the user information for username
Enter the new value, or press ENTER for the default
	Full Name []: 
	Room Number []: 
	Work Phone []: 
	Home Phone []: 
	Other []: 
Is the information correct? [Y/n] 

該命令將創建新用戶的家目錄,並將文件從/etc/skel目錄復制到用戶的主目錄。在主目錄中,用戶可以編寫,編輯和刪除文件和目錄。

或者:

sudo useradd -r -m -s /bin/bash dongyuanxin_2016150127

-r:建立系統賬號
-m:自動建立用戶的登入目錄
-s:指定用戶登入后所使用的shell

在 Ubuntu18.04 中,不會在創建用戶的時候自動提示設置密碼。需要手動執行:sudo passwd dongyuanxin_2016150127。來設置新用戶的密碼。

默認情況下,在Ubuntu上,sudo組的成員被授予sudo訪問權限。

如果您希望新創建的用戶具有管理權限,請將用戶添加到sudo組:

sudo usermod -aG sudo username

或者
編輯 /etc/sudoer 文件

Defaults        env_reset
Defaults        mail_badpass
Defaults        secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"
# Host alias specification
# User alias specification
# Cmnd alias specification
# User privilege specification
root    ALL=(ALL:ALL) ALL
# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL

# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL
# See sudoers(5) for more information on "#include" directives:
cjl    ALL=NOPASSWD:ALL
#includedir /etc/sudoers.d

添加用戶sudo 權限

通過GUI添加新用戶

如果您不喜歡命令行,則可以通過GUI添加新的用戶帳戶。

  1. 在“活動”屏幕中,搜索“用戶”,然后單擊“添加或刪除用戶並更改密碼”。
  2. 在新窗口中單擊Unlock按鈕,然后在出現提示時輸入用戶密碼。
  3. 單擊Add User按鈕,將出現“添加用戶”對話框:
  4. 選擇新用戶是標准用戶還是管理員用戶並輸入信息。完成后,單擊Add按鈕。

如何刪除用戶

如果不再需要用戶帳戶,可以從命令行或通過GUI刪除它。

從命令行刪除用戶

您可以使用兩個命令行工具來刪除用戶帳戶:userdel和deluser。在Ubuntu上,建議您使用deluser命令,因為它比userdel 更友好。

要刪除用戶而不刪除用戶文件,請運行:

sudo deluser username

如果要刪除並且用戶的家目錄和郵件使用--remove-home選項:

sudo deluser --remove-home username

通過GUI刪除用戶

  1. 在“活動”屏幕中,搜索“用戶”,然后單擊“添加或刪除用戶並更改密碼”。
  2. 在新窗口中單擊Unlock按鈕,然后在出現提示時輸入用戶密碼。輸入密碼后,該Unlock按鈕將變為綠色Add User按鈕。
  3. 單擊要刪除的用戶名,您將Remove User..在右下角看到一個紅色按鈕。
  4. 單擊Remove User..按鈕,系統將提示您是保留還是刪除用戶主目錄。單擊其中一個按鈕將刪除該用戶。

參考:
https://www.myfreax.com/how-to-add-and-delete-users-on-ubuntu-18-04/
linux如何將用戶添加到組中


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM