新建组:
NAME
groupadd - create a new group //groupadd用于创建组,/etc/group是组信息文件
SYNOPSIS
groupadd [options] group
如下新建一个名为develop_one的新组
[root@centos6 ~]#tail -2 /etc/group
stapdev:x:158:
tcpdump:x:72:
[root@centos6 ~]#groupadd develop_one
[root@centos6 ~]#tail -2 /etc/group
tcpdump:x:72:
develop_one:x:500:
[root@centos6 ~]#
*******************************************************************************************************
新建用户:
NAME
useradd - create a new user or update default new user information
//useradd用于创建新用户或者更新新用户默认信息,/etc/passwd是用户信息文件
SYNOPSIS
useradd [options] LOGIN
useradd -D
useradd -D [options]
如下新建tom和nokk两个新用户
[root@centos6 ~]#tail -2 /etc/passwd
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin
[root@centos6 ~]#useradd tom
[root@centos6 ~]#useradd nokk
[root@centos6 ~]#tail -4 /etc/passwd
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin
tom:x:500:501::/home/tom:/bin/bash
nokk:x:501:502::/home/nokk:/bin/bash
[root@centos6 ~]#
*******************************************************************************************************
给组添加用户和删除用户:
NAME
gpasswd - administer /etc/group and /etc/gshadow
//gpasswd命令可以管理/etc/group和/etc/gshadow文件
SYNOPSIS
gpasswd [option] group
OPTIONS
-a, --add user //给组添加用户
Add the user to the named group.
-d, --delete user //从组中删除用户
Remove the user from the named group.
如下把tom和nokk两个用户添加到develop_one组中
- 这里还可以使用usermod -a -G develop_one tom添加用户到组里
[root@centos6 ~]#tail -3 /etc/group
develop_one:x:500:
tom:x:501:
nokk:x:502:
[root@centos6 ~]#gpasswd -a tom develop_one
Adding user tom to group develop_one
[root@centos6 ~]#gpasswd -a nokk develop_one
Adding user nokk to group develop_one
[root@centos6 ~]#tail -3 /etc/group
develop_one:x:500:tom,nokk
tom:x:501:
nokk:x:502:
[root@centos6 ~]#
如下从develop_one组中把tom用户删除
[root@centos6 ~]#tail -3 /etc/group
develop_one:x:500:tom,nokk
tom:x:501:
nokk:x:502:
[root@centos6 ~]#gpasswd -d tom develop_one
Removing user tom from group develop_one
[root@centos6 ~]#tail -3 /etc/group
develop_one:x:500:nokk
tom:x:501:
nokk:x:502:
[root@centos6 ~]#
*******************************************************************************************************
赋值sgid和sticky权限
创建一个工作目录,给目录赋值sgid和sticky权限,使其不同用户在此目录下新建文件的属组都是该目录的
属组(这样就能保证在该目录下用户可以编辑修改其它用户创建的文件),并且用户只能删除自己创建的
文件,不能删除其它用户创建的文件
[root@centos6 var]#ls -ld wkhome/
drwxr-xr-x. 2 root root 4096 May 13 14:30 wkhome/
[root@centos6 var]#chown :develop_one wkhome/ //修改目录属组
[root@centos6 var]#chmod g+w wkhome/ //给目录属猪赋w权限
[root@centos6 var]#ls -ld wkhome/
drwxrwxr-x. 2 root develop_one 4096 May 13 14:30 wkhome/
[root@centos6 var]#
[root@centos6 var]#chmod g+s,o+t wkhome/ //给目录赋sgid和sticky权限
[root@centos6 var]#ls -ld wkhome/
drwxrwsr-t. 2 root develop_one 4096 May 13 14:30 wkhome/
[root@centos6 var]#
************************************************************************
[tom@centos6 wkhome]$whoami //切换到tom用户并在目录下创建文件
tom
[tom@centos6 wkhome]$touch tom.test
[tom@centos6 wkhome]$ll
total 0
-rw-rw-r--. 1 tom develop_one 0 May 13 14:34 tom.test
[tom@centos6 wkhome]$
************************************************************************
[nokk@centos6 wkhome]$whoami //切换到nokk用户并在目录下创建文件
nokk
[nokk@centos6 wkhome]$touch nokk.test
[nokk@centos6 wkhome]$ll
total 0
-rw-rw-r--. 1 nokk develop_one 0 May 13 14:34 nokk.test
-rw-rw-r--. 1 tom develop_one 0 May 13 14:34 tom.test
[nokk@centos6 wkhome]$
************************************************************************
[nokk@centos6 wkhome]$whoami //实现修改其它用户文件的功能
nokk
[nokk@centos6 wkhome]$ll
total 0
-rw-rw-r--. 1 nokk develop_one 0 May 13 14:34 nokk.test
-rw-rw-r--. 1 tom develop_one 0 May 13 14:34 tom.test
[nokk@centos6 wkhome]$echo "newline" >> tom.test
[nokk@centos6 wkhome]$cat tom.test
newline
[nokk@centos6 wkhome]$
************************************************************************
[nokk@centos6 wkhome]$whoami //不能删除其它用户文件
nokk
[nokk@centos6 wkhome]$ll
total 4
-rw-rw-r--. 1 nokk develop_one 0 May 13 14:34 nokk.test
-rw-rw-r--. 1 tom develop_one 8 May 13 14:36 tom.test
[nokk@centos6 wkhome]$rm -f tom.test
rm: cannot remove `tom.test': Operation not permitted
[nokk@centos6 wkhome]$rm -f nokk.test
[nokk@centos6 wkhome]$ll
total 4
-rw-rw-r--. 1 tom develop_one 8 May 13 14:36 tom.test
[nokk@centos6 wkhome]$