默认创建用户的时候将创建一个和用户相同名称的组, 这个选项关闭这个行为, 当这个选项使用的时候, 用户必须指定一个组 When this option is used, users by default will be placed in whatever group is specified in /etc/default/useradd. If no default group is defined, group 1 will be used.
This flag is used to create a system account. That is, a user with a UID lower than the value of UID_MIN defined in /etc/login.defs and whose password does not expire. Note that useradd will not create a home directory for such an user, regardless of the default setting in /etc/login.defs. You have to specify -m option if you want a home directory for a system account to be created. This is an option added by Red Hat
/etc/skel/ 目录下的文件将会覆盖默认的用户文件 The system administrator is responsible for placing the default user files in the /etc/skel/ directory. This version of useradd was modified by Red Hat to suit Red Hat user/group conventions.
涉及到的文件
1 2 3 4 5 6 7
/etc/passwd #User account information. /etc/shadow #Secure user account information. /etc/group #Group account information. /etc/gshadow #Secure group account information. /etc/default/useradd #Default values for account creation. /etc/skel/ #Directory containing default files. /etc/login.defs #Shadow password suite configuration.
退出值
The useradd command exits with the following values:
1 2 3 4 5 6 7 8 9 10
0 success 1 can't update password file 2 invalid command syntax 3 invalid argument to option 4 UID already in use (and no -o) 6 specified group doesn't exist 9 username already in use 10 can't update group file 12 can't create home directory 13 can't create mail spool
实例
新建用户加入组:
1
useradd –g sales jack –G company,employees //-g:加入主要组、-G:加入次要组
建立一个新用户账户,并设置 ID:
1
useradd duoli -u 544
需要说明的是,设定 ID 值时尽量要大于 500,以免冲突。因为 Linux 安装后会建立一些特殊用户,一般 0 到 499 之间的值留给 bin、mail 这样的系统账号。