1.用户建立
useradd 参数 用户名字
-u ##指定用户uid
-g ##指定用户初始组信息,这个组必须已经存在
-G ##指定附加组,这个组必须存在
-c ##用户说明
-d ##用户家目录
-s ##用户所使用的shell,/etc/shells记录了用户能使用shell的名字
2.用户删除
userdel -r 用户名称 -r表示删除用户信息及用户的系统配置
3.组的建立
groupadd -g ##建立组
groupdel 组名字 ##删除组
[root@localhost Desktop]# groupadd westos ##新建用户组westos
[root@localhost Desktop]# groupadd -g 888 linux ##新建用户组linux,并指定gid为888[root@localhost Desktop]# groupdel westos ##删除用户组
[root@localhost Desktop]# groupdel linux
[root@localhost Desktop]# useradd westos ##新建用户westos
[root@localhost Desktop]# userdel -r westos ##删除用户
[root@localhost Desktop]# useradd -u 666 westos ##新建用户westos,并指定uid为666
[root@localhost Desktop]# userdel -r westos
[root@localhost Desktop]# useradd -g 72 westos ##新建用户westos,并指定初始组gid为72
[root@localhost Desktop]# id westos ##查看westos用户组的信息
uid=1001(westos) gid=72(tcpdump) groups=72(tcpdump)
[root@localhost Desktop]# userdel -r westos
[root@localhost Desktop]# useradd -G 72 westos ##新建用户westos,并指定附加组为72
[root@localhost Desktop]# id westos ##查看westos用户组的信息
uid=1001(westos) gid=1001(westos) groups=1001(westos),72(tcpdump)
[root@localhost Desktop]# userdel -r westos
[root@localhost Desktop]# useradd -c "hello hi" westos ##新建用户,并指定用户说明
[root@localhost Desktop]# userdel -r westos
[root@localhost Desktop]# useradd -d /home/hi westos ##新建用户,并指定用户家目录
useradd: warning: the home directory already exists.
Not copying any file from skel directory into it.
[root@localhost Desktop]# userdel -r westos
userdel: /home/hi not owned by westos, not removing
4.用户信息更改
usermod 参数 用户
-l ##更改用户名称
-u ##更改uid
-g ##更改gid
-G ##更改附加组
-aG ##添加附加组
-c ##更改说明
-d ##更改家目录指定
-md ##更改家目录指定及家目录名称
-s ##更改shell
-L ##冻结帐号
-U ##解锁
[root@localhost Desktop]# usermod -u 777 westos ##更改用户uid为777
[root@localhost Desktop]# usermod -g 72 westos ##更改用户初始组gid为72,必须存在该组
[root@localhost Desktop]# usermod -G 21 westos ##更改用户附加组gid为21,必须存在该组
[root@localhost Desktop]# id westos ##查看用户组详细信息
uid=777(westos) gid=72(tcpdump) groups=72(tcpdump),21(slocate)
[root@localhost Desktop]# usermod -aG 1001 westos ##添加用户附加组
[root@localhost Desktop]# id westos
uid=777(westos) gid=72(tcpdump) groups=72(tcpdump),21(slocate),1001(westos)
[root@localhost Desktop]# usermod -c "hello" westos ##更改说明
[root@localhost Desktop]# usermod -md /home/hi westos ##更改家目录,以及家目录名称
[root@localhost Desktop]# usermod -L westos ##冻结帐号
[root@localhost Desktop]# usermod -U westos ##解锁帐号
[root@localhost Desktop]#
5.在系统中超级用户可以下放普通用户不能执行的操作给普通用户
下放权力配置文件:/etc/sudoers下放权力的方法
*)超级用户执行visudo进入编辑/etc/sudoers模式
*)格式:
获得权限用户 主机名称=(获得到的用户身份) 命令
test desktop0.example.com=(root) /usr/sbin/useradd
test用户能在desktop0.example.com以超级用户身份执行/usr/sbin/useradd
.执行下放权限命令
sudo 命令 ##如果第一次执行sudo需要输入当前用户密码
在/etc/sudoers中如果设置如下:
test desktop0.example.com=(root) NOPASSWD: /usr/sbin/useradd
表示用户调用sudo命令的时候不需要自己密码
[root@localhost Desktop]# su - student ##进入用户student
Last login: Wed Apr 5 10:59:58 EDT 2017 on pts/0
[student@localhost ~]$ useradd westos ##添加用户westos
-bash: /usr/sbin/useradd: Permission denied ##用户权限不足
[student@localhost ~]$exit ##退出登陆
logout
[root@localhost Desktop]# visudo ##编辑/etc/sudoers文件
[root@localhost Desktop]# su - student ##进入student用户
Last login: Wed Apr 5 10:02:58 EDT 2017 on pts/0
[student@localhost ~]$ sudo /usr/sbin/useradd westos ##重新执行sudo指令
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:
#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.
[sudo] password for student: ##输入密码,执行成功
[student@localhost ~]$
6.chage 参数 用户
-d ##用户密码组后一次修改的时间,如果设定成0,用户登陆系统后必须修改自己的密码-m ##最短有效期
-M ##最长有效期
-W ##警告期
-I ##用户非活跃天数
-E ##帐号到期日格式 -E "YYYY-MM-DD"