目录
用户管理
- 查看用户组
cat /etc/group
- 添加用户组
groupadd
groupadd -help
Usage: groupadd [options] GROUP
Options:
-f, --force exit successfully if the group already exists,
and cancel -g if the GID is already used
-g, --gid GID use GID for the new group
-h, --help display this help message and exit
-K, --key KEY=VALUE override /etc/login.defs defaults
-o, --non-unique allow to create groups with duplicate
(non-unique) GID
-p, --password PASSWORD use this encrypted password for the new group
-r, --system create a system account
eg:添加一个dtinone用户组,并设置GID为600
groupadd -g 610 devGroup
groupadd –g 611 testGroup
参数说明:
-g 指定新建用户组GID
GID为GroupId,即组ID,用来标识用户组的唯一标识符
UID为UserId,即用户ID,用来标识每个用户的唯一标示符
cat /etc/group
扩展:
用户组:将同一类用户设置为同一个组,如可将所有的系统管理员设置为admin组,便于分配权限,将某些重要的文件设置为所有admin组用户可以读写,这样可以进行权限分配。
每个用户都有一个唯一的用户id,每个用户组都有一个唯一的组id
删除一个用户组
groupdel
eg:
groupdel testGroup
用户管理
添加一个用户
useradd
useradd -help
useradd: invalid option -- 'h'
Usage: useradd [options] LOGIN
Options:
-b, --base-dir BASE_DIR base directory for the home directory of the
new account
-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
-e, --expiredate EXPIRE_DATE expiration date of the new account
-f, --inactive INACTIVE password inactivity period of the new account
-g, --gid GROUP name or ID of the primary group of the new
account
-G, --groups GROUPS list of supplementary groups of the new
account
-h, --help display this help message and exit
-k, --skel SKEL_DIR use this alternative skeleton directory
-K, --key KEY=VALUE override /etc/login.defs defaults
-l, --no-log-init do not add the user to the lastlog and
faillog databases
-m, --create-home create the user's home directory
-M, --no-create-home do not create the user's home directory
-N, --no-user-group do not create a group with the same name as
the user
-o, --non-unique allow to create users with duplicate
(non-unique) UID
-p, --password PASSWORD encrypted password of the new account
-r, --system create a system account
-s, --shell SHELL login shell of the new account
-u, --uid UID user ID of the new account
-U, --user-group create a group with the same name as the user
-Z, --selinux-user SEUSER use a specific SEUSER for the SELinux user mapping
eg: useradd -u 611 -g testGroup testUser
设置用户password
passwd userName #修改用户密码
eg:
passwd testUser
Changing password for user testUser.
New password:
BAD PASSWORD: it is too simplistic/systematic
BAD PASSWORD: is too simple
Retype new password:
passwd: all authentication tokens updated successfully.
参数说明:
passwd –参数 用户名
官方解释:
A simple entry in the global Linux-PAM configuration file for this service would be:
#
# passwd service entry that does strength checking of
# a proposed password before updating it.
#
passwd password requisite pam_cracklib.so retry=3
passwd password required pam_unix.so use_authtok
#
Note, other module types are not required for this application to function correctly.
OPTIONS
-k The option -k, is used to indicate that the update should only be for expired authentication tokens (passwords); the user wishes to keep
their non-expired tokens as before.
-l This option is used to lock the specified account and it is available to root only. The locking is performed by rendering the encrypted
password into an invalid string (by prefixing the encrypted string with an !).
--stdin
This option is used to indicate that passwd should read the new password from standard input, which can be a pipe.
-u This is the reverse of the -l option - it will unlock the account password by removing the ! prefix. This option is available to root only.
By default passwd will refuse to create a passwordless account (it will not unlock an account that has only "!" as a password). The force
option -f will override this protection.
-d This is a quick way to delete a password for an account. It will set the named account passwordless. Available to root only.
-e This is a quick way to expire a password for an account. The user will be forced to change the password during the next login attempt.
Available to root only.
-n This will set the minimum password lifetime, in days, if the user’s account supports password lifetimes. Available to root only.
-x This will set the maximum password lifetime, in days, if the user’s account supports password lifetimes. Available to root only.
-w This will set the number of days in advance the user will begin receiving warnings that her password will expire, if the user’s account
supports password lifetimes. Available to root only.
-i This will set the number of days which will pass before an expired password for this account will be taken to mean that the account is
inactive and should be disabled, if the user’s account supports password lifetimes. Available to root only.
-S This will output a short information about the status of the password for a given account. Available to root user only.
Remember the following two principles
Protect your password.
Don’t write down your password - memorize it. In particular, don’t write it down and leave it anywhere, and don’t place it in an unen-
crypted file! Use unrelated passwords for systems controlled by different organizations. Don’t give or share your password, in particular
to someone claiming to be from computer support or a vendor. Don’t let anyone watch you enter your password. Don’t enter your password to
a computer you don’t trust or if things Use the password for a limited time and change it periodically.
Choose a hard-to-guess password.
passwd through the calls to the pam_cracklib PAM module will try to prevent you from choosing a really bad password, but it isn’t fool-
proof; create your password wisely. Don’t use something you’d find in a dictionary (in any language or jargon). Don’t use a name (includ-
ing that of a spouse, parent, child, pet, fantasy character, famous person, and location) or any variation of your personal or account
name. Don’t use accessible information about you (such as your phone number, license plate, or social security number) or your environ-
ment. Don’t use a birthday or a simple pattern (such as backwards, followed by a digit, or preceded by a digit. Instead, use a mixture of
upper and lower case letters, as well as digits or punctuation. When choosing a new password, make sure it’s unrelated to any previous
password. Use long passwords (say at least 8 characters long). You might use a word pair with punctuation inserted, a passphrase (an
understandable sequence of words), or the first letter of each word in a passphrase.
These principles are partially enforced by the system, but only partly so. Vigilence on your part will make the system much more secure.
删除用户:
userdel
userdel testUser