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

Linux 命令整理 —— 用户管理
Linux基本命令天天用,想不熟悉都难,用户操作却不是天天都搞,多少容易有些遗漏,继续整理!


相关链接:
Linux 命令整理 —— 基本操作
Linux 命令整理 —— 用户管理


Linux用户管理以读、写、执行动作为权限,以用户组为单位,限制用户行为。对于文件的的操作,可以限制读、写、执行中的哪一种,也可以限制文件所有者、组用户、组外用户相应的权限。

所以,要建立用户,最好先确定其所在的组。
一、用户组操作
1. 创建用户组——groupadd
#新增deploy组
groupadd deploy


2. 修改用户组——groupmod
#将用户组deploy更名为deploy1
groupmod -n deploy1 deploy

注意是将已存在的deploy组更名为deploy1

3. 删除用户组——groupdel
#删除用户组deploy1
groupdel deploy1


4. 查看用户组——groups /etc/group
groups只能查看当前用户所在的组,以下是root用户所在的组。
引用
# groups
root bin daemon sys adm disk wheel


要看所有用户组信息,直接查看/etc/group:
引用
# cat /etc/group
root:x:0:root
bin:x:1:root,bin,daemon
daemon:x:2:root,bin,daemon
sys:x:3:root,bin,adm


二、用户操作
1. 创建用户——useradd
引用
# useradd
Usage: useradd [options] LOGIN

Options:
  -b, --base-dir BASE_DIR       base directory for the new user account
                                home directory
  -c, --comment COMMENT         set the GECOS field for the new user account
  -d, --home-dir HOME_DIR       home directory for the new user account
  -D, --defaults                print or save modified default useradd
                                configuration
  -e, --expiredate EXPIRE_DATE  set account expiration date to EXPIRE_DATE
  -f, --inactive INACTIVE       set password inactive after expiration
                                to INACTIVE
  -g, --gid GROUP               force use GROUP for the new user account
  -G, --groups GROUPS           list of supplementary groups for the new
                                user account
  -h, --help                    display this help message and exit
  -k, --skel SKEL_DIR           specify an alternative skel directory
  -K, --key KEY=VALUE           overrides /etc/login.defs defaults
  -m, --create-home             create home directory for the new user
                       &n