Ubuntu Desktop Server – 添加用户 / 删除用户和添加 sudo 权限
Ubuntu Desktop Server – 添加用户 / 删除用户和添加 sudo 权限
1. 添加新用户 yongqiang
Ubuntu users can add a new user using adduser
command. When you run the adduser
command to add a user account, you will have to give the new user account a password and name.
sudo adduser user-name
新用户添加成功后,使用 ls /home
检查新用户文件夹。
amax@amax-server:~$ sudo adduser yongqiang
[sudo] password for amax:
Adding user `yongqiang' ...
Adding new group `yongqiang' (1007) ...
Adding new user `yongqiang' (1007) with group `yongqiang' ...
Creating home directory `/home/yongqiang' ...
Copying files from `/etc/skel' ...
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for yongqiang
Enter the new value, or press ENTER for the default
Full Name []: yongqiang
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Is the information correct? [Y/n] Y
amax@amax-server:~$
strong@strong-sys:~$ sudo adduser yongqiang
[sudo] strong 的密码:
正在添加用户"yongqiang"...
正在添加新组"yongqiang" (1001)...
正在添加新用户"yongqiang" (1001) 到组"yongqiang"...
创建主目录"/home/yongqiang"...
正在从"/etc/skel"复制文件...
输入新的 UNIX 密码:
重新输入新的 UNIX 密码:
passwd:已成功更新密码
正在改变 yongqiang 的用户信息
请输入新值,或直接敲回车键以使用默认值
全名 []: yongqiang
房间号码 []:
工作电话 []:
家庭电话 []:
其它 []:
这些信息是否正确? [Y/n] Y
strong@strong-sys:~$
strong@strong-sys:~$ cd /home/
strong@strong-sys:/home$ ls
strong yongqiang
strong@strong-sys:/home$
strong@strong-sys:/home$ cd ~
strong@strong-sys:~$
You can also create a new user using the System Settings. Open System Settings and click on User Accounts. From here you can easily manage new Ubuntu user. Please note that you must have root privilege to add or delete a new user.
Once the user is created, you can easily use the newly created user account. Please note that when a new user is created, the adduser utility creates a new home directory named /home/username.
2. 用户 yongqiang 添加 sudo 权限
# User privilege specification
root ALL=(ALL:ALL) ALL
yongqiang ALL=(ALL:ALL) ALL
复制 root ALL=(ALL:ALL) ALL
至下一行,修改为 yongqiang ALL=(ALL:ALL) ALL
。
strong@strong-sys:~$ sudo vim /etc/sudoers
[sudo] strong 的密码:
strong@strong-sys:~$
strong@strong-sys:~$ cat /etc/sudoers
cat: /etc/sudoers: 权限不够
strong@strong-sys:~$
strong@strong-sys:~$ sudo cat /etc/sudoers
#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
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
yongqiang 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:
#includedir /etc/sudoers.d
strong@strong-sys:~$
原始文件信息:
deepnorth@deepnorth-amax:~$ cat /etc/sudoers
cat: /etc/sudoers: Permission denied
deepnorth@deepnorth-amax:~$
deepnorth@deepnorth-amax:~$ sudo cat /etc/sudoers
#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
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:
#includedir /etc/sudoers.d
deepnorth@deepnorth-amax:~$
3. 删除用户
If you wish to delete the newly created user, use the command deluser
to remove and delete the specific Ubuntu user.
Please note that when you delete a specific user account, it does not remove their respective home folder. You can delete the folder manually.
Ubuntu 删除用户需要注意的是,如果要删除的用户当前已登陆,是删除不掉的。必须注销掉当前用户,切换到其他用户下,才能删除。
sudo userdel username
sudo userdel -r username
删除成功后,系统无任何提示。
最好将用户留在系统上的文件也删除掉,可以使用 userdel -r username
来实现。
4. useradd – adduser
useradd
/ adduser
命令用来建立用户帐号,使用权限是超级用户。
利用 adduser
创建新用户 (adduser + username),在 /home
目录下会自动创建同名文件夹。
useradd
仅仅创建了一个用户名 (useradd + username),并没有在 /home
目录下创建同名文件夹,也没有创建密码。因此利用这个用户登录系统,是登录不了的。
可以用 (useradd -m + username) 的方式创建,它会在 /home
目录下创建同名文件夹,然后利用 (passwd + username)为指定的用户名设置密码。
5. Change user permissions
You can easily change and grant permissions for a specific user – change UID/GID values. Run the following command as required:
sudo chown -R root:root /home/username/
sudo mkdir /home/archived_users/
sudo mv /home/username /home/archived_users/
Not only this, you can also temporarily lock or unlock a specific user account using the following command:
sudo passwd -l username
sudo passwd -u username
References
[1] Yongqiang Cheng, Ubuntu Desktop Server – 添加用户 / 删除用户和添加 sudo 权限
今天的文章ubuntu添加用户并赋予管理员权限_ubuntu添加sudo用户「建议收藏」分享到此就结束了,感谢您的阅读。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/89671.html