centos下用户 用户组相关操作


查找相关文章:centos group

root用户状态下

#查看所有用户可以cat一下
cat /etc/passwd
#查看所有用户组可以cat一下
cat /etc/group

用户操作

1.useradd

Option Description

-c '<comment>' <comment> can be replaced with any string. This option is generally used to specify the full name of a user.

-d<home-dir> Home directory to be used instead of default /home/<username>/

-e<date> Date for the account to be disabled in the format YYYY-MM-DD

-f<days> Number of days after the password expires until the account is disabled. If 0 is specified, the account is disabled immediately after the password expires. If -1 is specified, the account is not be disabled after the password expires.

-g<group-name> Group name or group number for the user's default group. The group must exist prior to being specified here.

-G<group-list> List of additional (other than default) group names or group numbers, separated by commas, of which the user is a member. The groups must exist prior to being specified here.

 -a, --append                  append the user to the supplemental GROUPS

                                mentioned by the -G option without removing

                                him/her from other groups

-m Create the home directory if it does not exist.

-M Do not create the home directory.

-n Do not create a user private group for the user.

-r Create a system account with a UID less than 500 and without a home directory

-p<password> The password encrypted with crypt

-s User's login shell, which defaults to /bin/bash

-u<uid> User ID for the user, which must be unique and greater than 499


常用的如

useradd -s /bin/nonogin -m -d /home/www -G sftp www

-s /bin/nonogin 即不允许用户shell登陆

-d /home/www 指定用户根目录

-m 如果用户目录不存在则创建

-G sftp 把用户加入到sftp用户组

末尾为用户名成


2.passwd <username> 给用户设置密码

passwd www

3.usermod

   -c<备注>  修改用户帐号的备注文字。 

 -d登入目录>  修改用户登入时的目录。 

 -e<有效期限>  修改帐号的有效期限。 

 -f<缓冲天数>  修改在密码过期后多少天即关闭该帐号。 

 -g<群组>  修改用户所属的群组。 

 -G<群组>  修改用户所属的附加群组。 

 -l<帐号名称>  修改用户帐号名称。 

 -L  锁定用户密码,使密码无效。 

 -s<shell>  修改用户登入后所使用的shell。 

 -u<uid>  修改用户ID。 

 -U  解除密码锁定。

  -a 加入到其他组 并保留原来的组