Go to main content

手册页部分 8:系统管理命令

退出打印视图

更新时间: 2022年7月27日 星期三
 
 

usermod(8)

名称

useradd, roleadd, usermod, rolemod - administer an existing or add a new user or role login to the system

用法概要

useradd [-A authorization[,authorization...]]
     [-b base_dir | -d dir] [-c 
comment] [-e expire]
     [-f inactive] [-g group] [-G group[,group]...]
     [-K key=value] [-m [-k skel_dir]] [-p projname]
     [-z yes | no | nodelegation]
     [-P profile[,profile...]]
     [-R role [, role...]]
     [-s shell] [-S repository] [-u uid [-o]] username
useradd -D [-A authorization[,authorization...]]
     [-b base_dir] [-s 
shell [-k skel_dir]] [-e expire]
     [-f inactive] [-g 
group] [-K key=value] [-p projname]
     [-P profile[,profile...]]
roleadd [-A authorization[,authorization...]]
     [-b base_dir | -d dir] [-c 
comment] [-e expire]
     [-f inactive] [-g group] [-G group [,group]...]
     [-K key=value] [-m [-k skel_dir]] [-p projname]
     [-z yes | no | nodelegation]
     [-P profile[,profile...]]
     [-s shell] [-S 
repository] [-u uid [-o]] rolename
roleadd -D [-A authorization[,authorization...]]
     [-b base_dir] [-s 
shell [-k skel_dir]] [-e expire]
     [-f inactive] [-g 
group] [-K key=value] [-p projname]
     [-P profile[,profile...]]
usermod [-A authorization[,authorization...]]
     [-d dir] [-c comment] [-e expire]
     [-f inactive] [-g group] [-G group [,group]...]
     [-K key=value] [-m [-k skel_dir]] [-p projname]
     [-z yes | no | nodelegation]
     [-P profile[,profile...]]
     [-R role [, role...]]
     [-l new_username]
     [-q qualifier]
     [-s shell] [-S repository] [-u uid [-o]] username
rolemod [-A authorization[,authorization...]]
     [-d dir] [-c comment] [-e expire]
     [-f inactive] [-g group] [-G group [,group]...]
     [-K key=value] [-m [-k skel_dir]] [-p projname]
     [-z yes | no | nodelegation]
     [-P profile[,profile...]]
     [-l new_rolename]
     [-q qualifier]
     [-s shell] [-S repository] [-u uid [-o]] rolename

描述

The useradd and roleadd utilities add a new user or role entry to the passwd(5), shadow(5), and user_attr(5) databases in the files or ldap repository.

The usermod and rolemod utilities modify a user's or role's login definition on the system.They change the definition of the specified login and make the appropriate login-related changes to the appropriate repository and corresponding file system changes.

The –A and –P options respectively assign authorizations and profiles to the user or role.–R 选项向用户分配角色。(不能将角色指定给其他角色。)The –p option associates a project with a user or role.The –K option adds a key=value pair to the user_attr entry for the user or role.使用多个 –K 选项可添加多个 key=value 对。

The –G option creates supplementary group memberships for the user or role.The –m option creates the home directory for the user or role if requested.在执行 passwd(1) 命令之前,新登录名将保持锁定状态。

Specifying the –D to useradd or roleadd with the –s, –k, –g, –b, –f, –e, –A, –P, –p, –R, or –K option (or any combination of these options) sets the default values for the respective fields.请参见下文中的 –D 选项。Subsequent useradd or roleadd commands without the –D option use these arguments.

另外,可以指定在运行时动态应用的缺省设置。对于使用 –S ldap 创建的帐户,可以使用 –S ldap 和特殊值 default@ 作为帐户名指定任何 –K 属性的缺省值。由于 default@ 帐户不适用于登录,因此被自动锁定。可以在 policy.conf(5) 中指定其他缺省值。

useradd and usermod require that usernames be in the format described in passwd(5).如果不满足这些限制,将显示一条警告消息。

roleadd and rolemod require that role names be a string of no more than eight bytes consisting of characters from the set of alphabetic characters, numeric characters, period (.), underscore (_), and hyphen (-).The first character should be alphabetic and the name should contain at least one lower case alphabetic character.如果不满足这些限制,将写入一条警告消息。A future Solaris release might refuse to accept role names that do not meet these requirements.Role names must contain at least one character and must not contain a colon (:) or a newline (\n).

When used with usermod or rolemod the –A, –G, –K, –P, and –R options may take a list of values to add or remove to the granted set using the [+|-] prefix.A prefix + adds the value to the existing set; a prefix - removes the value from the existing granted set.To remove all values an empty list must be specified using '', or any appropriate equivalent according to the shell in use.

An administrator must be granted the User Management Profile to be able to create a new user or role.管理员必须具有 "User Security"(用户安全)配置文件才能修改现有用户的安全属性。要修改现有角色的非安全属性,用户需要 "User Management"(用户管理)配置文件。The authorizations required to set the various fields in passwd, shadow, and user_attr can be found in passwd(5), shadow(5), and user_attr(5).分配组和项目所需的授权可以在 group(5)project(5) 中找到。

选项

支持以下选项:

–A [+|-]authorization

一个或多个以逗号分隔的在 auth_attr(5) 中定义的授权。只有对授权具有 grant 权限的用户或角色才能将授权分配给帐户。

–b base_dir

新登录起始目录的基目录(请参见下文中的 –d 选项)。创建新用户帐户时,base_dir 必须已存在,否则还需要指定 –m 选项或 –d 选项。

–c comment

任意文本字符串。它通常为登录项的简短说明,当前用作存储用户全名的字段。该信息存储在用户的 passwd 条目中。

–d dir | server:dir

指定新用户的起始目录路径。如果未指定任何服务器名称,则在 passwd(5) 数据库中维护指定的目录。

可选服务器名称指定起始目录所在的主机。采用此格式的条目依赖于自动挂载程序,并在 auto_home 映射中进行维护。路径 /home/ usernamepasswd(5) 数据库中维护。用户随后引用 /home/username 时,自动挂载程序将在 /home/ username 中挂载指定的目录。

–D

Display the default values for group, base_dir, skel_dir, shell, inactive, expire, proj, projname, zfshome, and key=value pairs.When used with the –g, –b, –f, –e, –A, –P, –p, –R, or –K options, the –D option sets the default values for the specified fields.缺省值包括:

FIELD
DEFAULT VALUE
group
other (GID of 1)
base_dir
/export/home
skel_dir
/etc/skel
shell
/usr/bin/bash
inactive
0
expire
null
auths
null
profiles
null
auth_profiles
null
proj
3
projname
default
zfshome
yes
key=value(在 user_attr(5) 中定义的键/值对))
not present
roles
null
–e expire

指定登录名的失效日期。此日期过后,没有任何用户能够访问此登录名。到期选项参数是使用模板文件 /etc/datemsk 中包含的日期格式之一输入的日期。See getdate(3C).

如果所选日期包含空格,必须将其放在引号中。例如,您可以输入 10/6/90October 6, 1990。Null 值 (" ") 会使到期日期处于无效状态。此选项对创建临时登录名非常有用。

–f inactive

在声明该 ID 无效之前,允许登录 ID 在连续两次使用之间间隔的最大天数。正常值为正整数。0 值会使此状态无效。

–g group

现有组的整数 ID 或字符串名称。如果不带 –D 选项,它将定义新用户的主组成员关系并成为缺省组。可通过调用 useradd –D –g group 重置此缺省值。Solaris 操行系统保留了 GID 0-99 供将来分配。

–G [+|-]group

现有组的整数 ID 或字符串名称。它定义新用户的补充组成员关系。使用 –g–G 选项指定的 group 之间的重复项将被忽略。指定的组数不能大于 NGROUPS_MAX。Solaris 操行系统保留了 GID 0-99 供将来分配。

–K key[+|-]=value

要添加到用户的属性中的 key=value 对。可使用多个 –K 选项添加多个 key=value 对。可以使用通用 –K 选项以及相应键来代替特定的隐式键选项(–A–P–R–p)。有关有效的 key=value 对列表,请参见 user_attr(5)。对于此选项,“type” 键不是有效键。键不能重复。

–k skel_dir

A directory that contains skeleton information (such as .profile) that can be copied into a new user's home directory.该目录必须已存在。系统提供的 /etc/skel 目录可用于此用途。

–m

如果新用户的起始目录不存在,则创建该目录。如果该目录已存在,group 必须对其具有读取、写入和执行权限,其中 group 为用户的主组。如果指定给 –d 选项的服务器名称是远程主机,系统将不尝试创建起始目录。

When the -z option is not passed and if the directory does not already exist and the parent directory is the mount point of a ZFS dataset, then a child of that dataset will be created and mounted at the specified location.授予用户创建 ZFS 快照并对其进行提升的权限。新创建的数据集将继承其父项的加密设置。如果该数据集已加密,将授予用户更改其包装密钥的权限。

新创建的目录被创建为多级别数据集。

–l new_loginname

The new login name for a user or role.Only valid with usermod and rolemod.

–o

此选项允许 UID 重复(不唯一)。

–P [+|-]profile

一个或多个由逗号分隔的在 prof_attr(5) 中定义的的执行配置文件。

–p projname

与添加的用户关联的项目的名称。请参见 project(5) 中定义的 projname 字段。

–q qualifier

用于限定扩展属性(通过 –K–P–A–R 选项指定)适用位置的主机或 netgroup 的名称。需要前缀 @ 来指示限定符是 netgroup 名称。The –q option is only valid if the login account is maintained in the LDAP name service.

–R [+|-]role

一个或多个由逗号分隔的在 user_attr(5) 中定义的的执行配置文件。不能将角色指定给其他角色。

–s shell

程序的全路径名,登录时可用作用户的 shell。如果未指定,则将缺省为以前使用 –D –s 选项配置的任何值。如果未使用 –D –s 选项设置缺省值,则将使用 /usr/bin/bashshell 的值必须为一个有效的可执行文件。

–z zfshome

Select if a new separate ZFS filesystem is created as the user/role home directory.The option can be set as the system wide default or set per user/role.

yes

User has their own ZFS filesystem with the mount, create, and snapshot zfs allow delegations

nodelegation

User has their own ZFS filesystem but with no delegations

no

Users home is a simple directory

–S repository

The repository specifies which name service will be updated.有效的系统信息库包括 filesldap。缺省的系统信息库为 files。系统信息库为 files 时,授权、配置文件和角色可存在于其他名称服务系统信息库中,并可以分配给 files 系统信息库中的用户。When the repository is ldap, all the assignable attributes must be present in the ldap repository, and both the LDAP server and client must be configured with enableShadowUpdate.See ldapclient(8) for details.

–u uid

新用户的 UID。This UID must be a non-negative decimal integer below MAXUID as defined in <sys/param.h>.UID 缺省为高于当前分配的最大编号的下一个可用(唯一)编号。例如,如果分配了 UID 100、105 和 200,则下一个缺省 UID 号为 201。UIDs 0-99 are reserved for allocation by the Solaris Operating System.

示例

示例 1 Creating a User

The following command adds adds the user with the default configuration

# useradd jdoe

This results in the system assigning the next available uid, the user will not have a home directory created for them.

示例 2 Creating a User with a specified uid and create a local home directory

The following command adds adds the user and creates their home directory in the default location

# useradd -u 1001 -m jdoe
示例 3 Creating a User with a local home directory that is not a ZFS filesystem

The following command adds adds the user and creates their home directory in the default location

# useradd -z no -m jdoe

This results in new user with a directory in the default location as their home directory.

示例 4 Set the system default for the type of home directory

The following command sets the system wide default to be a directory rather than a per-user ZFS file system as the default home directory type.

# useradd -D -z no
示例 5 为用户分配特权

以下命令添加的特权会影响用户初始可继承权限集的高分辨率时间。

# usermod -K defaultpriv=basic,proc_clock_highres jdoe

此命令将在 user_attr 中生成以下条目:

jdoe::::type=normal;defaultpriv=basic,proc_clock_highres
示例 6 从用户的限制权限集中删除特权

以下命令删除的特权允许指定用户创建目录的硬链接以及取消目录链接。

# usermod -K limitpriv=all,!sys_linkdir jdoe

此命令将在 user_attr 中生成以下条目:

jdoe::::type=normal;defaultpriv=basic,limitpriv=all,!sys_linkdir
示例 7 从用户的基本特权集中删除特权

以下命令删除的特权允许指定用户检查用户会话以外的进程。

# usermod -K defaultpriv=basic,!proc_session jdoe

此命令将在 user_attr 中生成以下条目:

jdoe::::type=normal;defaultpriv=basic,!proc_session;limitpriv=all
示例 8 将角色分配给用户

以下命令将角色分配给用户。The role must have been created prior to running this command.

# usermod -R mailadm jdoe

此命令将在 user_attr 中生成以下条目:

jdoe::::type=normal;roles=mailadm;defaultpriv=basic;limitpriv=all
示例 9 授予用户若干权限

以下命令授予 solaris.zone.manage 授权、"Project Management"(项目管理)权限配置文件,将限制特权设置为基本特权,并将 mailadm 角色分配给用户。

# usermod -A 'solaris.zone.manage' -P 'Project Management' \
     -K limitpriv=basic -R mailadm -S files jdoe_ldap

此命令将在 user_attr 中生成以下条目:

jdoe_ldap::::auths=solaris.zone.manage;profiles=ProjectManagement;
limitpriv=basic;roles=mailadm
示例 10 授予用户已验证权限配置文件

以下命令将已验证权限配置文件添加到可信用户。

# usermod -K auth_profiles+="Network Security" jdoe
示例 11 删除用户的所有配置文件

以下命令删除直接授予用户的所有配置文件。用户仍将拥有通过 policy.conf(5) 中的 PROFS_GRANTED 键授予的权限配置文件。

# usermod -P "" jdoe
示例 12 Set the root account to be a role

Set the root account to be a role and assign the role to a user.

# usermod -K type=role root
# usermod -R +root jdoe

This will change the root account to be a role and add the root role to any existing role assignments for the user jdoe.

示例 13 Set the root account to be a direct login account

Change the root account from being a role to a direct login account.

# rolemod -K type=normal root

This will change the root account to no longer be a role, so direct login to it on the console will be allowed.

示例 14 Deleting a User

Delete the user and remove their home directory.

# userdel -r jdoe

This will remove the user entry from the passwd, shadow, group and user_attr databases, and will delete the users home directory and all of its content.

退出状态

In case of an error, these commands print an error message and exit with one of the following values:

1

无权执行尝试的操作。

2

命令语法无效。将显示 usermod 命令的用法消息。

3

为选项提供的参数无效。

4

使用 –u 选项指定的 giduid 已在使用中。

5

passwordshadow 文件相互不一致。可使用 pwconv(8) 更正可能的错误。请参见 passwd(5)shadow(5)

6

要修改的登录项不存在,giduid 不存在。

7

grouppasswdshadow 文件缺失。

9

组名或用户名已在使用中。

10

无法更新 passwdshadowuser_attr 文件。

11

空间不足,无法移动起始目录(–m 选项)。

12

无法创建、删除或移动新的起始目录。

13

请求的登录名已在使用中。

14

意外失败。

16

无法更新组数据库。

17

无法更新项目数据库。

18

授权不足。

19

没有角色。

20

没有配置文件。

21

没有特权。

22

没有标签。

23

没有组。

24

系统未运行 Trusted Extensions。

25

没有项目。

26

无法更新 auto_home

文件

/etc/datemsk

/etc/passwd

/etc/shadow

/etc/group

/etc/skel

/usr/include/limits.h

/etc/user_attr

属性

有关下列属性的说明,请参见 attributes(7)

属性类型
属性值
可用性
system/core-os
接口稳定性
Committed(已确定)

另请参见

auths(1), passwd(1), profiles(1), roles(1), getdate(3C), auth_attr(5), group(5), passwd(5), prof_attr(5), project(5), shadow(5), user_attr(5), attributes(7), labels(7), rbac(7), groupadd(8), groupdel(8), groupmod(8), grpck(8), logins(8), pwck(8), pwconv(8), roledel(8), userdel(8)

Managing User Accounts and User Environments in Oracle Solaris 11.4

Working With Oracle Solaris 11.4 Directory and Naming Services: LDAP

诊断

如果出现错误,useradd 将显示错误消息并以非零状态退出。If the error occurred because LDAP is misconfigured, the error message is preceded by "LDAP configuration problem".

以下情况表示指定的 login 已在使用中:

UX: useradd: ERROR: login is already in use. Choose another.

以下情况表示使用 –u 选项指定的 uid 不唯一:

UX: useradd: ERROR: uid uid is already in use. Choose another.

以下情况表示尚未创建使用 –g 选项指定的 group

UX: useradd: ERROR: group group does not exist. Choose another.

以下情况表示使用 –u 选项指定的 uid 处于保留的 UID 范围 (0-99) 之内:

UX: useradd: WARNING: uid uid is reserved.

The following indicates that the uid specified with the –u option exceeds MAXUID as defined in <sys/param.h>:

UX: useradd: ERROR: uid uid is too big. Choose another.

以下情况表示 /etc/passwd/etc/shadow 文件不存在:

UX: useradd: ERROR: Cannot update system files - login cannot be created.

以下情况表示执行此命令的用户没有足够的授权来执行操作:

UX: useradd: ERROR: Permission denied.

The following indicates that an invalid directory was specified in a useradd command:

UX: invalid_directory is not a valid directory. Choose another.

附注

These utilities add or modify definitions in the passwd, shadow, group, project, and user_attr databases in the scope (default or specified).They will verify the uniqueness of the user name (or role) and user id and the existence of any group names specified against the external name service.