ubuntu 16.04 desktop + server LTS - 添加 / 删除用户

ubuntu 16.04 desktop + server LTS - 添加 / 删除用户

How to add & delete users on Ubuntu 16.04?

添加新用户 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 username

新用户添加成功后,使用 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.

用户 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:~$

删除用户

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 来实现。

useradd / adduser

useradd / adduser 命令用来建立用户帐号,使用权限是超级用户。
利用 adduser 创建新用户 (adduser + username),在 /home 目录下会自动创建同名文件夹。
useradd 仅仅创建了一个用户名 (useradd + username),并没有在 /home 目录下创建同名文件夹,也没有创建密码。因此利用这个用户登录系统,是登录不了的。
可以用 (useradd -m + username) 的方式创建,它会在 /home 目录下创建同名文件夹,然后利用 (passwd + username)为指定的用户名设置密码。

change user permissions

You can easily change and grant permissions for a specific user - change UID/GID values. Run the following command as required:

扫描二维码关注公众号,回复: 3639692 查看本文章
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

猜你喜欢

转载自blog.csdn.net/chengyq116/article/details/83088257