3.2 linux用户管理 : 用户CRUD 【就是对/etc/passwd数据库的修改】

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/one_chao/article/details/89138094

3.2 linux用户管理 : 用户CRUD 【就是对/etc/passwd数据库的修改】

思维导图

1.增加用户useradd adduser

$ useradd / adduser <userName> ##增加用户
$ passwd <userName>##设置密码
$ userdel <userName> ##删除用户 只有debian 的sudo 和RedHat 的wheel 的用户组才能执行
$ su <userName> ##切换用户
$ id <userName> ##查看指定用户的uid,gid,groupid

2.查看指定用户的uid,gid,groupid

$ id
uid=1000(sgx) gid=1000(sgx) groups=1000(sgx),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),108(lpadmin),124(sambashare)

3.修改用户-修改home目录(-d)

-d 指定用户的home 目录
$ usermod user2 -d /home/user2
$ mkdir /home/user2
$ su user2 ##就会切入user2的目录下

3.修改用户-指定账户的过期时间(-e)

$ sudo usermod user2 -e 2017-10-10 ##指定过期时间
[sudo] password for sgx:
$ su user2
Password: 
Your account has expired(过期); please contact your system administrator
su: Authentication failure

3.修改用户-强行使用GROUP作为新的主group(-g)

$ groupadd testGroup ##新建group
$ sudo usermod user3 -g testGroup ##把user3指定为testGroup分组
$ su user3 ##切换
$ groups   ##查看分组
testGroup

3.修改用户-增加user一个的groups的list(-G)

$ usermod user3 -G sudo ## 给user3用户添加了sudo组
$ su user3
$ sudo reboot           ##可以执行sudo命令

3.修改用户-指定登陆的名字(修改用户名)(-l)

user3@ubuntu:~$ sudo usermod user4 -l chao313 ##指定user4更改为chao313
user3@ubuntu:~$ su user4
No passwd entry for user 'user4'
user3@ubuntu:~$ su chao313                     ##只能是chao313登陆
Password:

4.usermod 命令详解

  -c, --comment COMMENT         new value of the GECOS field
  -d, --home HOME_DIR           new home directory for the user account   ##为用户新建一个home directorry
  -e, --expiredate EXPIRE_DATE  set account expiration date to EXPIRE_DATE ##指定账户的过期时间,格式为 YYYY-MM-DD
  -f, --inactive INACTIVE       set password inactive after expiration
                                to INACTIVE
  -g, --gid GROUP               force use GROUP as new primary group       ##强行使用GROUP作为新的主group
  -G, --groups GROUPS           new list of supplementary(增加的) GROUPS   ##增加user一个的groups的list    
  -a, --append                  append the user to the supplemental GROUPS
                                mentioned by the -G option without removing
                                him/her from other groups
  -h, --help                    display this help message and exit
  -l, --login NEW_LOGIN         new value of the login name                ##指定登陆的名字(修改用户名)
  -L, --lock                    lock the user account                      ##lock account
  -m, --move-home               move contents of the home directory to the ##移动home文件夹到新的位置和-d一起使用
                                new location (use only with -d)
  -o, --non-unique              allow using duplicate (non-unique) UID
  -p, --password PASSWORD       use encrypted password for the new password ##使用加密的密码作为新的密码
  -R, --root CHROOT_DIR         directory to chroot into
  -s, --shell SHELL             new login shell for the user account
  -u, --uid UID                 new UID for the user account
  -U, --unlock                  unlock the user account
  -v, --add-subuids FIRST-LAST  add range of subordinate uids
  -V, --del-subuids FIRST-LAST  remvoe range of subordinate uids
  -w, --add-subgids FIRST-LAST  add range of subordinate gids
  -W, --del-subgids FIRST-LAST  remvoe range of subordinate gids
  -Z, --selinux-user SEUSER     new SELinux user mapping for the user account

图形界面注意:
对于Linux图形界面,增加用户的时候必须要同时创建/home/<user_name> 并更换用户所属权
—> 否则没有权限登陆

#useradd <userName>
#passwd <userName>
#mkdir /home/<userName>
#chown <userName>:<userName> /home/<userName>

猜你喜欢

转载自blog.csdn.net/one_chao/article/details/89138094