Linux用户和组管理命令

来源:互联网 发布:洛丽塔电影知乎 编辑:程序博客网 时间:2024/05/21 06:38

1、添加用户:useradd

[root@mini2 ~]# useradd test
2、添加组:groupadd

[root@mini2 ~]# groupadd testgroup
3、为新用户test添加组testgroup:usermod -g      usermod修改用户信息

[root@mini2 ~]# usermod -g testgroup tes

usermod详解:

[root@mini2 ~]# usermod --helpUsage: usermod [options] LOGINOptions:  -c, --comment COMMENT         new value of the GECOS field                #添加描述信息  -d, --home HOME_DIR           new home directory for the user account     #为用户指定主目录  -e, --expiredate EXPIRE_DATE  set account expiration date to EXPIRE_DATE  -f, --inactive INACTIVE       set password inactive after expiration                                to INACTIVE  -g, --gid GROUP               force use GROUP as new primary group  -G, --groups GROUPS           new list of supplementary GROUPS           #为用户设置其他组  -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                       #锁定  -m, --move-home               move contents of the home directory to the                                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  -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                     #解锁  -Z, --selinux-user            new SELinux user mapping for the user account

4、为用户添加描述信息:usermod -c

[root@mini2 ~]# usermod -c "this is a test user" test
5、添加一个用户,并设置组,并添加描述信息:

useradd -g 组 -c "描述信息" 用户
6、设置用户密码:passwd

[root@mini2 ~]# passwd test更改用户 test 的密码 。新的 密码:无效的密码: 它基于字典单词无效的密码: 过于简单重新输入新的 密码:passwd: 所有的身份验证令牌已经成功更新。
7、修改用户登录名:

[root@mini2 ~]# usermod -l newtest test
8、将用户添加到其他组中:

[root@mini2 ~]# usermod -G sys,root test
添加到了sys组与root组中。

9、查看用户组信息:groups

[root@mini2 ~]# groups testtest : testgroup root sys
10、为用户移除指定的组:gpasswd -d  用户  组

[root@mini2 ~]# gpasswd -d test sysRemoving user test from group sys[root@mini2 ~]# gpasswd -d test rootRemoving user test from group root[root@mini2 ~]# groups testtest : testgroup
11、修改组名称:groupmod -n 新组名  组名

[root@mini2 ~]# groupmod -n testg testgroup[root@mini2 ~]# groups testtest : testg
12、为用户配置sudo权限:

用root用户编辑 vi /etc/sudoers
在文件的如下位置,为test用户添加一行即可


root    ALL=(ALL)       ALL     
test    ALL=(ALL)       ALL


然后,test用户就可以用sudo来执行系统级别的指令















0 0