Ubuntu用户管理

目录
  1. 创建用户 - adduser
  2. 删除用户 - deluser
  3. 新增用户组 - addgroup
  4. 删除用户组 - delgroup
  5. 其他

创建用户 - adduser

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
root@iZ28rwmhep0Z:~# adduser xyz
Adding user `xyz' ...
Adding new group `xyz' (1000) ...
Adding new user `xyz' (1000) with group `xyz' ...
Creating home directory `/home/xyz' ...
Copying files from `/etc/skel' ...
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for xyz
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

查看帮助

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
xyz@iZ28rwmhep0Z:~$ adduser -help
adduser [--home DIR] [--shell SHELL] [--no-create-home] [--uid ID]
[--firstuid ID] [--lastuid ID] [--gecos GECOS] [--ingroup GROUP | --gid ID]
[--disabled-password] [--disabled-login] [--encrypt-home] USER
Add a normal user
adduser --system [--home DIR] [--shell SHELL] [--no-create-home] [--uid ID]
[--gecos GECOS] [--group | --ingroup GROUP | --gid ID] [--disabled-password]
[--disabled-login] USER
Add a system user
adduser --group [--gid ID] GROUP
addgroup [--gid ID] GROUP
Add a user group
addgroup --system [--gid ID] GROUP
Add a system group
adduser USER GROUP
Add an existing user to an existing group
general options:
--quiet | -q don't give process information to stdout
--force-badname allow usernames which do not match the
NAME_REGEX[_SYSTEM] configuration variable
--help | -h usage message
--version | -v version number and copyright
--conf | -c FILE use FILE as configuration file

删除用户 - deluser

deluser -r xx 加-r可删除该用户home目录,直接删除不删目录

新增用户组 - addgroup

-help查看详细参数

删除用户组 - delgroup

-help查看详细参数
su命令可切换到root命令, su otherUser 则切换至其他用户,对于有sudo权限的用户可直接使用sudo执行root身份的命令

其他

Linux用户及用户组都有对应的id,UID为用户id,GID为用户组id。

使用id可查看uid,gid,groups信息

1
2
xyz@iZ28rwmhep0Z:~$ id
uid=1000(xyz) gid=1000(xyz) groups=1000(xyz)

使用groups可查看当前用户所在用户组
group信息在/etc/group下

/etc/passwd 可查看账户信息

1
2
3
4
xyz@iZ28rwmhep0Z:~$ cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
列数 含义 说明
1 用户名
2 密码 原密码位置,现密码在/etc/shadow,这里为字母x
3 UID 用户ID
4 GID 用户组ID
5 现不用
6 用户home目录 登陆后的位置
7 登录Shell 用户登录所用的Shell