linux(centos)之useradd命令

useradd建立用户的过程
useradd不加任何参数创建用户时,系统首先读取添加用户配置文件/etc/login.defs和/etc/default/useradd,根据这两个配置文件中定义的规则添加用户,然后会向/etc/passwd和/etc/group文件添加用户和用户组记录,同时/etc/passwd和/etc/group对应的加密文件也会自动生成记录,接着系统会自动在/etc/default/useradd文件设定的目录下建立用户主目录,最后复制/etc/skel目录中的所有文件到新用户的主目录中,这样一个新的用户就建立完成了。

注意:使用passwd命令给useradd新建立的用户指定登录密码,注意如果不指定登录密码那么useradd新增的用户是无法登录的。

Options:
  -b, --base-dir BASE_DIR       base directory for the home directory of the new account,指定主目录,注意该主目录所在目录(-b的参数值)需要使得新建立的用户具有rx权限,否则新建立的用户登录后无法进入该主目录-亚强,参见案例八。
  -c, --comment COMMENT         GECOS field of the new account新增用户指定用户的注释信息,参见案例九。

  -d, --home-dir HOME_DIR       home directory of the new account
  -D, --defaults                print or change default useradd configuration,查看useradd若未指定相关参数情况下的默认值,参见案例一,这些默认值存储在/etc/default/useradd文件。
  -e, --expiredate EXPIRE_DATE  expiration date of the new account,用YYYYY-MM-DD格式指定一个账户过期的日期 ,参见案例十。
  -f, --inactive INACTIVE       password inactivity period of the new account案例十一:定这个帐户密码过期后多少天这个账户被禁用;0表示密码一过期就立即禁 用,-1表示禁用这个功能,这里可以设置一个整数,单位为天,如果不设置该值,那么一般默认为空。
  -g, --gid GROUP               name or ID of the primary group of the new account,新增用户指定用户的基本组,参见案例六。当通过useradd命令创建新用户时,可以通过-g参数指定已存在的某个组为其主组,若没有使用-g参数,则系统自动创建名称和用户名相同的组作为该用户的主组(前提是variable in /etc/login.defs的USERGROUPS_ENAB属性值为yes),如命令手册的useradd关于-g参数的描述所示:
-g, --gid GROUP
The group name or number of the user′s initial login group. The
group name must exist. A group number must refer to an alreadyexisting group.If not specified, the bahavior of useradd will depend on the USERGROUPS_ENAB variable in /etc/login.defs. If this variable is
set to yes (or -U/--user-group is specified on the command line), a group will be created for the user, with the same name as her
loginname. If the variable is set to no (or -N/--no-user-group is specified on the command line), useradd will set the primary group of the new user to the value specified by the GROUP variable in
/etc/default/useradd, or 100 by default.(亚强:如果设置为yes则自动新建一个组,如果设置为no,则基本组的值为/etc/default/useradd中GROUP参数的值,通常centos6.5初始化该值为GROUP=100)参见案例六

  -G, --groups GROUPS           list of supplementary groups of the new  account新增用户,指定用户的附属组。 指定用户除登录组之外所属的一个或多个附加组,若同时指定多个附加组

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值