日期:2014-05-16  浏览次数:20763 次

细说Linux的用户和组之管理命令详解

Linux系统以组Group方式管理用户


用户和组的配置和管理命令主要有:


用户管理

主要命令
useradd???? 新建用户
usermod???? 修改用户
userdel???? 删除用户
newusers??? 新建用户(批量)
passwd????? 修改用户密码
chsh??????? 设置用户的shell
chage?????? 设置用户密码有效期
newgrp????? 将用户添加至某个组
id????????? 打印用户id和所属组id
who???????? 打印当前登录用户
whoami????? 打印当前用户名称和id

?


命令详情如下(从命令手册截取):


useradd

NAME 名称
?????? useradd - create a new user or update default new user information

SYNOPSIS 用法
?????? useradd [options] LOGIN
?????? useradd -D
?????? useradd -D [options]

DESCRIPTION 概述
?????? When invoked without the -D option, the useradd command creates a new
?????? user account using the values specified on the command line plus the
?????? default values from the system. Depending on command line options, the
?????? useradd command will update system files and may also create the new
?????? user′s home directory and copy initial files.

?????? By default, a group will also be created for the new user (see -g, -N,
?????? -U, and USERGROUPS_ENAB).

?

?

usermod

NAME
?????? usermod - modify a user account

SYNOPSIS
?????? usermod [options] LOGIN

DESCRIPTION
?????? The usermod command modifies the system account files to reflect the
?????? changes that are specified on the command line.

?

?

userdel

NAME
?????? userdel - delete a user account and related files

SYNOPSIS
?????? userdel [options] LOGIN

DESCRIPTION
?????? The userdel command modifies the system account files, deleting all entries
?????? that refer to the user name LOGIN. The named user must exist.???????
??????

newusers

NAME
?????? newusers - update and create new users in batch

SYNOPSIS
?????? newusers [options new_users]

DESCRIPTION
?????? The newusers command reads a file of user name and clear-text password pairs
?????? and uses this information to update a group of existing users or to create new
?????? users. Each line is in the same format as the standard password file (see
?????? passwd(5)) with the exceptions explained below:

?????? pw_name:pw_passwd:pw_uid:pw_gid:pw_gecos:pw_dir:pw_shell

?????? pw_name
?????????? This is the name of the user.

?????????? It can be the name of a new user or the name of an existing user (or an
?????????? user created before by newusers). In case of an existing user, the user′s
?????????? information will be changed, otherwise a new user will be created.??????????
???????????
??????????
passwd
NAME
?????? passwd - update user’s authentication tokens

SYNOPSIS
?????? passwd? [-k]? [-l]? [-u? [-f]] [-d] [-n mindays] [-x maxdays] [-w warndays] [-i
?????? inactivedays] [-S] [--stdin] [username]

DESCRIPTION
?????? The passwd utility is used to update user’s authentication token(s).

?????? This task is achieved through calls to the Linux-PAM and Libuser? API.?? Essen-
?????? tially, it initializes itself as a "passwd" service with Linux-PAM and utilizes
?????? configured password modules to authenticate and then update a user’s? password.
???????
??????
chsh

NAME
?????? chsh - change your login shell

SYNOPSIS
?????? chsh [-s shell] [-l] [-u] [-v] [username]

DESCRIPTION
?????? chsh is used to change your login shell.? If a shell is not given on the command line, chsh prompts for one.

?? VALID SHELLS
?????? chsh wil