MySQL, Oracle, Linux, 软件架构及大数据技术知识分享平台

网站首页 > linux / 正文

linux命令之用户管理

2024-11-26 15:33 huorong linux 3 ℃ 0 评论

linux用户管理

用户信息文件

在linux中的/etc/passwd文件中保存着linux的所有用户信息

root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin

以冒号分隔分为七列

第一列为用户名

第二列为密码标志 x表示有密码,密码存在/etc/shadow文件中

第三列为用户ID 0是超级用户 1-499是系统用户 500-65535是普通用户

第四列为组id 对应着/etc/group文件中的记录

第五列为用户说明

第六列为用户家目录

第七列为登录shell

密码文件

用户的密码存在/etc/shadow文件中

bin:*:15980:0:99999:7:::
daemon:*:15980:0:99999:7:::
adm:*:15980:0:99999:7:::

以冒号分隔分为九列

第一列 用户名

第二列 加密后的密码

第三列 密码最近修改时间 (距离1970年1月1日的天数)

第四列 两次密码的修改间隔时间

第五列 密码有效期

第六列 密码到期前的警告时间

第七列 密码到期后的宽限天数

第八 密码失效时间

第九 保留字段

组信息文件

组信息存在/etc/group文件中

root:x:0:
bin:x:1:bin,daemon
daemon:x:2:bin,daemon

以冒号分隔分为四列

第一列 组名

第二列 组密码

第三列 组ID

第四列 此组中支持的其他用户

用户命令

添加用户

添加用户使用useradd命令

useradd [option] 用户名

  -c, --comment COMMENT         GECOS field of the new account  说明
  -d, --home-dir HOME_DIR       home directory of the new account  家目录
  -g, --gid GROUP               name or ID of the primary group of the new 
                                account   初始组id或组名,默认是与用户名相同
  -G, --groups GROUPS           list of supplementary groups of the new
                                account   附加组
  -p, --password PASSWORD       encrypted password of the new account  密码
  -r, --system                  create a system account   创建一个系统用户
  -s, --shell SHELL             login shell of the new account  登录shell,默认是bin/bash
  -u, --uid UID                 user ID of the new account   用户id

修改用户信息

usermod [options] 用户名

-c, --comment COMMENT         GECOS field of the new account  说明
  -d, --home-dir HOME_DIR       home directory of the new account  家目录
  -g, --gid GROUP               name or ID of the primary group of the new 
                                account   初始组id或组名,默认是与用户名相同
  -G, --groups GROUPS           list of supplementary groups of the new
                                account   附加组
  -p, --password PASSWORD       encrypted password of the new account  密码
  -r, --system                  create a system account   创建一个系统用户
  -s, --shell SHELL             login shell of the new account  登录shell,默认是bin/bash
  -u, --uid UID                 user ID of the new account   用户id

删除用户

userdel [-r] 用户名

-r 表示删除用户的同时删除家目录

切换用户

su - 用户名

密码设置修改

#密码设置
passwd 用户名

#对于普通用户来说,只可以修改当前用户密码,不需要指定用户名
passwd

组命令

添加组

groupadd 组名

删除组

groupdel 组名

把用户加入组或者删除组

gpasswd [options] 组名

-a, --add USER                add USER to GROUP 把用户加入组
-d, --delete USER             remove USER from GROUP 把用户移出组

Tags:linux如何删除用户

控制面板
您好,欢迎到访网站!
  查看权限
网站分类
最新留言