- 增加用户
-
adduser user_name |
增加新用户 |
adduser -g group_name user_name |
增加新用户并指定组 |
- . 只有root或具备sudo权限的用户才能创建用户
- . 用户创建时,会创建同名的用户组,该用户组是用户默认的用户组;也可以创建时指定用户组
- . 每个用户都在/etc/home下有对应的家目录
- . 一般情况下,家目录和用户名保持一致;也可以创建的时候使用-d指定额外的家目录名字,但是不推荐
- . 创建的提示,会设置密码和用户基本信息;对应的用户信息位于/etc/passwd;说是密码,其实是看不到密码信息的
-
cnplaman@pla:~/Desktop$ sudo adduser glboy
Adding user `glboy' ...
Adding new group `glboy' (1002) ...
Adding new user `glboy' (1002) with group `glboy' ...
Creating home directory `/home/glboy' ...
Copying files from `/etc/skel' ...
New password:
Retype new password:
passwd: password updated successfully
Changing the user information for glboy
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
cnplaman@pla:~/Desktop$ ls /home
cnplaman glboy plaman
- 删除用户
- . 只有root或具备sudo权限的用户才能删除用户
- . 默认保留用户目录和用户拥有的文件;[]为什么?
- . 使用--remove-all-files就不需要指定--remove-home
-
--remove-home |
删除用户的家目录 |
--remove-all-files |
删除用户所拥有的文件 |
--group |
删除组 |
-
root@pla:/home/cnplaman# deluser --remove-all-files glboy
Looking for files to backup/remove ...
...
Removing files ...
Removing user `glboy' ...
Warning: group `glboy' has no more members.
Done.
root@pla:/home/cnplaman# id glboy
id: ‘glboy’: no such user
root@pla:/home/cnplaman# ls /home/
cnplaman plaman
- []常见错误提示
- . Only root may remove a user or group from the system.:非root用户不能删除
- . superman is not in the sudoers file. This incident will be reported.:非sudo权限用户不能删除
- . user stu20221001 is currently used by process
32675:用户还在系统进程中,应退出当前用户状态,返回到root或具有sudo权限的用户再删除;如果还是删除不了,说明利用用户切换命令登陆过该用户。切换到该用户,退出登陆log
out,再使用root或具备sudo权限的用户删除
- 修改用户
- 查看用户
-
who |
查看当前登陆的所有用户[0表示本机用户,其它为用户对应IP地址] |
whoami |
查看当前登陆的用户 |
id [username] |
查看用户UID和GID;如果不指定用户,则查看当前用户 |
-
cnplaman@pla:~$ who
cnplaman tty2 2022-12-24 09:32 (tty2)
cnplaman@pla:~$ whoami
cnplaman
cnplaman@pla:~$ id
uid=1000(cnplaman) gid=1000(cnplaman) groups=1000(cnplaman),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),122(lpadmin),134(lxd),135(sambashare)
cnplaman@pla:~$ id glboy
uid=1002(glboy) gid=1002(glboy) groups=1002(glboy)
cnplaman@pla:~/Desktop$ id glpla
id: ‘glpla’: no such user
- []查看所有用户
-
cnplaman@pla:~/Desktop$ cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
...
cnplaman:x:1000:1000:cnplaman,,,:/home/cnplaman:/bin/bash
plaman:x:1001:1001:,,,:/home/plaman:/bin/bash
glboy:x:1002:1002:,,,:/home/glboy:/bin/bash
- []如果whoami拆开为who am i执行会如何?