Linux創(chuàng)建用戶有兩條命令:adduser和useradd,對應(yīng)著兩條刪除用戶的命令:deluser和userdel
這兩種命令之間的區(qū)別:
adduser:會自動為創(chuàng)建的用戶指定主目錄、系統(tǒng)shell版本,會在創(chuàng)建時輸入用戶密碼。
useradd:需要使用參數(shù)選項指定上述基本設(shè)置,如果不使用任何參數(shù),則創(chuàng)建的用戶無密碼、無主目錄、沒有指定shell版本。
這里只記錄使用adduser命令創(chuàng)建用戶
1.創(chuàng)建一個用戶adduser dilei
root@C87654321123456:/home# adduser dilei
Adding user `dilei' ...
Adding new group `dilei' (1000) ...
Adding new user `dilei' (1000) with group `dilei' ...
Creating home directory `/home/dilei' ...
Copying files from `/etc/skel' ...
New password: // 這里讓輸入密碼
Retype new password: // 再次輸入密碼
passwd: password updated successfully
Changing the user information for dilei
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] y
2.創(chuàng)建完成后執(zhí)行sudo mkdir a創(chuàng)建文件夾的時候提示:dilei is not in the sudoers file(用戶dilei不在sudoers文件夾中)
root@C87654321123456:/home# su dilei // 切到dilei用戶下
dilei@C87654321123456:/home$ sudo mkdir a // 創(chuàng)建目錄
[sudo] password for dilei:
dilei is not in the sudoers file. This incident will be reported.
dilei@C87654321123456:/home$ exit // 退出dilei用戶回到root用戶下
root@C87654321123456:/home# vim /etc/sudoers // 修改sudoers文件
3. vim /etc/sudoers打開sudoers文件找到root ALL=(ALL:ALL) ALL 在下方添加 用戶名 ALL=(ALL:ALL) ALL因為是只讀模式,輸入wq!強制保存并退出。
# User privilege specification
root ALL=(ALL:ALL) ALL
dilei ALL=(ALL:ALL) ALL // 這里添加了一條
4.再次切換到dilei用戶使用sudo mkdir a 創(chuàng)建一個名稱為a的文件夾 可以看到創(chuàng)建成功
root@C87654321123456:/home# su dilei
dilei@C87654321123456:/home$ sudo mkdir a
[sudo] password for dilei:
dilei@C87654321123456:/home$ ls
a dilei shiiko
dilei@C87654321123456:/home$
刪除用戶
userdel -r dilei用戶相關(guān)文件一起刪除
注:本文為搬運后二次加工產(chǎn)品
版權(quán)聲明:本文為CSDN博主「taolusi」的原創(chuàng)文章,遵循CC 4.0 BY-SA版權(quán)協(xié)議,轉(zhuǎn)載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/taolusi/article/details/81304057