作业一:
1) 新建用户natasha,uid为1000,gid为555,备注信息为“master”
[[email protected] ~]# vim /etc/passwd
按‘a’进入编辑状态,修改如下
natasha:x:1000:555:master:/home/natasha:/bin/bash
按‘Esc’,后输入‘:wq!’退出
或: [[email protected] ~]# useradd -u 1000 -g 555 -c master natasha
2) 修改natasha用户的家目录为/Natasha
按‘a’进入编辑状态,修改如下
natasha:x:1000:555:master:/home/Natasha:/bin/bash
按‘Esc’,后输入‘:wq!’退出
或:[[email protected] ~]# usermod -d Natasha natasha
3) 查看用户信息配置文件的最后一行
[[email protected] ~]# vim /etc/passwd
[[email protected] ~]# tail -1 /etc/passwd
natasha:x:1000:555:master:/home/Natasha:/bin/bash
4) 为natasha用户设置密码“123”
[[email protected] ~]# echo ‘123‘ | passwd --stdin natasha
Changing password for user natasha.
passwd: all authentication tokens updated successfully.
5) 查看用户密码配置文件的最后一行
[[email protected] ~]# tail -1 /etc/shadow
natasha:$1$DYh6oru/$QS9PA88Smpx.vrscOkmts/:17310:0:99999:7:::
6) 将natasha用户账户锁定
[[email protected] ~]# vim /etc/passwd
natasha:x:1000:555:master:/home/Natasha:/bin/bash
改为:natasha:x:1000:555:master:/home/Natasha:/sbin/nologin
或:[[email protected] ~]#usermod –L natasha
7) 将natasha用户账户解锁
[[email protected] ~]# vim /etc/passwd
natasha:x:1000:555:master:/home/Natasha:/sbin/nologin
改为:natasha:x:1000:555:master:/home/Natasha:/bin/bash
或:[[email protected] ~]#usermod –U natasha
8) 新建组police,gid为999
[[email protected] ~]# groupadd -g 999 police
groupadd: GID ‘999‘ already exists
[[email protected] ~]# groupadd -g 9999 police
9) 查看组配置文件的最后一行
[[email protected] ~]# tail -1 /etc/group
police:x:9999:
10) 将natasha用户加入police组
[[email protected] ~]# usermod -g police natasha
11) 修改police组的组名为jingcha
[[email protected] ~]#usermod –L natasha
police:x:9999:natasha
改为:jingcha:x:9999:natasha
或:[[email protected] ~]#groupmod -n jingcha police
12) 删除natasha用户,连家目录和邮箱一起删除
[[email protected] ~]# userdel -r natasha
userdel: group natasha not removed because it is not the primary group of user natasha.
userdel: /var/spool/mail/natasha not owned by natasha, not removing
userdel: natasha home directory (/home/Natasha) not found
[[email protected] ~]# userdel -rf natasha
userdel: user ‘natasha‘ does not exist
13) 删除jingcha组
[[email protected] ~]# groupdel jingcha
作业二:
1) 在用户的主目录下创建目录test,进入test创建空文件file1
[[email protected] ~]# cd ~
[[email protected] ~]# mkdir test
[[email protected] ~]# touch test/filel
2) 以长格式形式显示文件信息,注意文件的权限和所属用户和组
[[email protected] ~]# ll test/filel
-rw-r--r--. 1 root root 0 May 24 01:49 test/filel
3) 为文件file1设置权限,使其他用户可以对此文件进行写操作。
[[email protected] ~]# chmod o=w test/filel
4) 查看设置结果
[[email protected] ~]# ll test/filel
-rw-r---w-. 1 root root 0 May 24 01:49 test/filel
5) 取消同组用户对文件file1的读取权限,并查看设置结果。
[[email protected] ~]# chmod g=- test/filel
[[email protected] ~]# ll test/filel
-rw-----w-. 1 root root 0 May 24 01:49 test/filel
6) 用数字表示法为文件file设置权限,所有者可读、可写、可执行,所属组用户和其他用户只具有读和执行的权限。设置完成后查看设置结果。
[[email protected] ~]# chmod 755 test/filel
[[email protected] ~]# ll test/filel
-rwxr-xr-x. 1 root root 0 May 24 01:49 test/filel
7) 用数字形式更改文件file1的权限,使所有者只能读取此文件。其他任何用户都没有权限。查看设置结果。
[[email protected] ~]# chmod 400 test/filel
[[email protected] ~]# ll test/filel
-r--------. 1 root root 0 May 24 01:49 test/filel
8) 回到上层目录,查看test的权限
[[email protected] ~]# cd /root/test
[[email protected] test]# ll test
ls: cannot access test: No such file or directory
[[email protected] test]# cd -
/root
[[email protected] ~]# ll -d test
drwxr-xr--. 2 root root 19 May 24 01:49 test
9) 为其他用户添加对此目录的写权限
[[email protected] ~]# chmod o+w test
[[email protected] ~]# ll -d test
drwxr-xrw-. 2 root root 19 May 24 01:49 test
作业三:
以操作文件的方式,新建一个用户alex
作业四:
1) 新建目录/test/dir,属主为tom,数组为group1,/test目录的权限为777
[[email protected] ~]# mkdir -p /test/dir/
[[email protected] ~]# useradd tom
[[email protected] ~]# groupadd group1
[[email protected] ~]# chown tom:group1 /test/dir/
[[email protected] ~]# chmod 777 /test/dir/
[[email protected] ~]# ll -d /test/dir/
drwxrwxrwx. 2 tom group1 6 May 24 02:33 /root/test/dir/
2) 新建用户jack,切换到jack用户下,验证jack用户对dir目录的rwx权限(开启另外一个终端,依次修改dir目录的others权限)
[[email protected] ~]# useradd jack
[[email protected] ~]# su - jack
[[email protected] ~]$ su - root
Password:
Last login: Tue May 23 19:04 PDT 2017 on :0
[[email protected] ~]# chomd o+w /test/dir/
3)将jack加入group1组,验证jack用户对dir目录的rwx权限(开启另外一个终端,依次修改dir目录的group权限)
[[email protected] ~]# usermod -g group1 jack
[[email protected] ~]# exit
[[email protected] ~]$ su - root
Password:
[[email protected] ~]# id jack
uid=1005(jack) gid=1006(group1) groups=1006(group1)
[[email protected] dir]$ ll -d /test/dir
drwxr-xr-x. 2 root root 6 May 24 05:13 /test/dir
[[email protected] dir]$ touch cd /test/dir
touch: cannot touch ‘cd’: Permission denied
[[email protected] dir]$ cd /test/dir
4)切换到tom用户,验证tom用户对dir目录的rwx权限(开启另外一个终端,依次修改dir目录的user权限)
[email protected] ~]# su - tom
Last login: Wed May 24 05:08:04 PDT 2017 on pts/0
[[email protected] ~]$ ll -d /test/dir/
drwxr-xr-x. 2 root root 6 May 24 05:13 /test/dir/
[[email protected] ~]$ touch /test/dir/tom.txt
touch: cannot touch ‘/test/dir/tom.txt’: Permission denied
[[email protected] ~]$ cd /test/dir/
[[email protected] dir]$ su - root
Password:
Last login: Wed May 24 05:13:00 PDT 2017 on pts/0
[[email protected] ~]# chmod o+w /test/dir
5)在dir目录内新建文件tom.txt,属主为tom,属组为group1,/test目录的权限为777
[[email protected] dir]$ touch /test/dir/tom.txt
[[email protected] dir]$ touch /test/dir/tom.txt
[[email protected] dir]$ chown -R tom:group1 /test/dir/tom.txt
chown: changing ownership of ‘/test/dir/tom.txt’: Operation not permitted
[[email protected] dir]$ su - root
Password:
Last login: Wed May 24 05:35:36 PDT 2017 on pts/1
[[email protected] ~]# chown -R tom:group1 /test/dir/tom.txt
[[email protected] ~]# su - tom
Last login: Wed May 24 05:31:40 PDT 2017 on pts/0
[[email protected] ~]$ chmod 777 /test/dir/tom.txt
6)新建用户rose,切换到rose用户下,验证rose用户对tom.txt的rwx权限(开启另外一个终端,依次修改tom.txt的others权限来配合验证过程)
7)将rose加入group1组,在rose用户下,验证rose用户对tom.txt的rwx权限(开启另外一个终端,依次修改tom.txt的group1权限来配合验证过程)
8)切换到tom用户,验证tom用户对tom.txt的rwx权限(开启另外一个终端,依次修改tom.txt的user权限来配合验证过程)
作业五:
1) 新建用户natasha,uid为1000,gid为555,备注信息为“master”
[[email protected] ~]# vim /etc/passwd
按‘a’进入编辑状态,修改如下
natasha:x:1000:555:master:/home/natasha:/bin/bash
按‘Esc’,后输入‘:wq!’退出
或: [[email protected] ~]# useradd -u 1000 -g 555 -c master natasha
2) 修改natasha用户的家目录为/Natasha
按‘a’进入编辑状态,修改如下
natasha:x:1000:555:master:/home/Natasha:/bin/bash
按‘Esc’,后输入‘:wq!’退出
或:[[email protected] ~]# usermod -d Natasha natasha
3) 查看用户信息配置文件的最后一行
[[email protected] ~]# vim /etc/passwd
[[email protected] ~]# tail -1 /etc/passwd
natasha:x:1000:555:master:/home/Natasha:/bin/bash
4) 为natasha用户设置密码“123”
[[email protected] ~]# echo ‘123‘ | passwd --stdin natasha
Changing password for user natasha.
passwd: all authentication tokens updated successfully.
5) 查看用户密码配置文件的最后一行
[[email protected] ~]# tail -1 /etc/shadow
natasha:$1$DYh6oru/$QS9PA88Smpx.vrscOkmts/:17310:0:99999:7:::
6) 将natasha用户账户锁定
[[email protected] ~]# vim /etc/passwd
natasha:x:1000:555:master:/home/Natasha:/bin/bash
改为:natasha:x:1000:555:master:/home/Natasha:/sbin/nologin
或:[[email protected] ~]#usermod –L natasha
7) 将natasha用户账户解锁
[[email protected] ~]# vim /etc/passwd
natasha:x:1000:555:master:/home/Natasha:/sbin/nologin
改为:natasha:x:1000:555:master:/home/Natasha:/bin/bash
或:[[email protected] ~]#usermod –U natasha
8) 新建组police,gid为999
[[email protected] ~]# groupadd -g 999 police
groupadd: GID ‘999‘ already exists
[[email protected] ~]# groupadd -g 9999 police
9) 查看组配置文件的最后一行
[[email protected] ~]# tail -1 /etc/group
police:x:9999:
10) 将natasha用户加入police组
[[email protected] ~]# usermod -g police natasha
11) 修改police组的组名为jingcha
[[email protected] ~]#usermod –L natasha
police:x:9999:natasha
改为:jingcha:x:9999:natasha
或 :[[email protected] ~]#groupmod -n jingcha police
12) 删除natasha用户,连家目录和邮箱一起删除
[[email protected] ~]# userdel -r natasha
userdel: group natasha not removed because it is not the primary group of user natasha.
userdel: /var/spool/mail/natasha not owned by natasha, not removing
userdel: natasha home directory (/home/Natasha) not found
[[email protected] ~]# userdel -rf natasha
userdel: user ‘natasha‘ does not exist
13) 删除jingcha组
[[email protected] ~]# groupdel jingcha
作业六:
1) 在用户的主目录下创建目录test,进入test创建空文件file1
[[email protected] ~]# cd ~
[[email protected] ~]# mkdir test
[[email protected] ~]# touch test/filel
2) 以长格式形式显示文件信息,注意文件的权限和所属用户和组
[[email protected] ~]# ll test/filel
-rw-r--r--. 1 root root 0 May 24 01:49 test/filel
3) 为文件file1设置权限,使其他用户可以对此文件进行写操作。
[[email protected] ~]# chmod o=w test/filel
4) 查看设置结果,
[[email protected] ~]# ll test/filel
-rw-r---w-. 1 root root 0 May 24 01:49 test/filel
5) 取消同组用户对文件file1的读取权限,并查看设置结果。
[[email protected] ~]# chmod g=- test/filel
[[email protected] ~]# ll test/filel
-rw-----w-. 1 root root 0 May 24 01:49 test/filel
6) 用数字表示法为文件file设置权限,所有者可读、可写、可执行,所属组用户和其他用户只具有读和执行的权限。设置完成后查看设置结果。
[[email protected] ~]# chmod 755 test/filel
[[email protected] ~]# ll test/filel
-rwxr-xr-x. 1 root root 0 May 24 01:49 test/filel
7) 用数字形式更改文件file1的权限,使所有者只能读取此文件。其他任何用户都没有权限。查看设置结果。
[[email protected] ~]# chmod 400 test/filel
[[email protected] ~]# ll test/filel
-r--------. 1 root root 0 May 24 01:49 test/filel
8) 回到上层目录,查看test的权限
[[email protected] ~]# cd /root/test
[[email protected] test]# ll test
ls: cannot access test: No such file or directory
[[email protected] test]# cd -
/root
[[email protected] ~]# ll -d test
drwxr-xr--. 2 root root 19 May 24 01:49 test
9) 为其他用户添加对此目录的写权限
[[email protected] ~]# chmod o+w test
[[email protected] ~]# ll -d test
drwxr-xrw-. 2 root root 19 May 24 01:49 test
作业七:
以操作文件的方式,新建一个用户alex
作业八:
1) 新建目录/test/dir,属主为tom,数组为group1,/test目录的权限为777
[[email protected] ~]# mkdir -p /test/dir/
[[email protected] ~]# useradd tom
[[email protected] ~]# groupadd group1
[[email protected] ~]# chown tom:group1 /test/dir/
[[email protected] ~]# chmod 777 /test/dir/
[[email protected] ~]# ll -d /test/dir/
drwxrwxrwx. 2 tom group1 6 May 24 02:33 /root/test/dir/
2) 新建用户jack,切换到jack用户下,验证jack用户对dir目录的rwx权限(开启另外一个终端,依次修改dir目录的others权限)
[[email protected] ~]# useradd jack
[[email protected] ~]# su - jack
[[email protected] ~]$ su - root
Password:
Last login: Tue May 23 19:04 PDT 2017 on :0
[[email protected] ~]# chomd o+w /test/dir/
3)将jack加入group1组,验证jack用户对dir目录的rwx权限(开启另外一个终端,依次修改dir目录的group权限)
[[email protected] ~]# usermod -g group1 jack
[[email protected] ~]# exit
[[email protected] ~]$ su - root
Password:
[[email protected] ~]# id jack
uid=1005(jack) gid=1006(group1) groups=1006(group1)
[[email protected] dir]$ ll -d /test/dir
drwxr-xr-x. 2 root root 6 May 24 05:13 /test/dir
[[email protected] dir]$ touch cd /test/dir
touch: cannot touch ‘cd’: Permission denied
[[email protected] dir]$ cd /test/dir
4)切换到tom用户,验证tom用户对dir目录的rwx权限(开启另外一个终端,依次修改dir目录的user权限)
[email protected] ~]# su - tom
Last login: Wed May 24 05:08:04 PDT 2017 on pts/0
[[email protected] ~]$ ll -d /test/dir/
drwxr-xr-x. 2 root root 6 May 24 05:13 /test/dir/
[[email protected] ~]$ touch /test/dir/tom.txt
touch: cannot touch ‘/test/dir/tom.txt’: Permission denied
[[email protected] ~]$ cd /test/dir/
[[email protected] dir]$ su - root
Password:
Last login: Wed May 24 05:13:00 PDT 2017 on pts/0
[[email protected] ~]# chmod o+w /test/dir
5)在dir目录内新建文件tom.txt,属主为tom,属组为group1,/test目录的权限为777
[[email protected] dir]$ touch /test/dir/tom.txt
[[email protected] dir]$ touch /test/dir/tom.txt
[[email protected] dir]$ chown -R tom:group1 /test/dir/tom.txt
chown: changing ownership of ‘/test/dir/tom.txt’: Operation not permitted
[[email protected] dir]$ su - root
Password:
Last login: Wed May 24 05:35:36 PDT 2017 on pts/1
[[email protected] ~]# chown -R tom:group1 /test/dir/tom.txt
[[email protected] ~]# su - tom
Last login: Wed May 24 05:31:40 PDT 2017 on pts/0
[[email protected]n ~]$ chmod 777 /test/dir/tom.txt
6)新建用户rose,切换到rose用户下,验证rose用户对tom.txt的rwx权限(开启另外一个终端,依次修改tom.txt的others权限来配合验证过程)
7)将rose加入group1组,在rose用户下,验证rose用户对tom.txt的rwx权限(开启另外一个终端,依次修改tom.txt的group1权限来配合验证过程)
8)切换到tom用户,验证tom用户对tom.txt的rwx权限(开启另外一个终端,依次修改tom.txt的user权限来配合验证过程)