美文网首页
用户组和权限示例

用户组和权限示例

作者: sunnowyli | 来源:发表于2018-09-07 18:30 被阅读0次

1、复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其它用户均没有任何访问权限。

>>> ll /etc/skel/ -a

        drwxr-xr-x.  2 root root  62 Apr 26 17:20 .

        drwxr-xr-x. 89 root root 8192 Sep  5 17:17 ..

        rw-r--r--.  1 root root  18 Aug  3  2017 .bash_logout

        rw-r--r--.  1 root root  193 Aug  3  2017 .bash_profile

        rw-r--r--.  1 root root  231 Aug  3  2017 .bashrc

>>> cp -r /etc/skel/ /home/tuser1 ; chmod -R go-rwx /home/tuser1

>>> ll /home/tuser1/ -a

        drwx------.  2 root root  62 Sep  7 17:16 .

        drwxr-xr-x. 16 root root 208 Sep  7 17:16 ..

        -rw-------.  1 root root  18 Sep  7 17:16 .bash_logout

        -rw-------.  1 root root 193 Sep  7 17:16 .bash_profile

        -rw-------.  1 root root 231 Sep  7 17:16 .bashrc

2、编辑/etc/group文件,添加组hadoop。

>>>tail -1  /etc/group 

        hadoop:x:4007:

3、手动编辑/etc/passwd文件新增一行,添加用户hadoop,其基本组ID为hadoop组的id号;其家目录为/home/hadoop。

>>>tail -1 /etc/passwd

        hadoop:x:4007:4007::/home/hadoop:/bin/bash

4、复制/etc/skel目录为/home/hadoop,要求修改hadoop目录的属组和其它用户没有任何访问权限。

>>> mkdir /home/hadoop ; install /etc/skel/.* -m u=rw,go-rwx /home/hadoop/ &> /dev/null

>>> ll /home/hadoop/ -a

        drwxr-xr-x.  2 root root  62 Sep  7 17:37 .

        drwxr-xr-x. 18 root root 236 Sep  7 17:34 ..

        -rw-------.  1 root root  18 Sep  7 17:37 .bash_logout

        -rw-------.  1 root root 193 Sep  7 17:37 .bash_profile

        -rw-------.  1 root root 231 Sep  7 17:37 .bashrc

>>>mkdir /home/hadoop ;install /etc/skel/.*  -m 600 /home/hadoop &> /dev/null

>>>ll hadoop/ -a

        drwxr-xr-x.  2 root root  62 Sep  7 17:38 .

        drwxr-xr-x. 18 root root 236 Sep  7 17:34 ..

        -rw-------.  1 root root  18 Sep  7 17:38 .bash_logout

        -rw-------.  1 root root 193 Sep  7 17:38 .bash_profile

        -rw-------.  1 root root 231 Sep  7 17:38 .bashrc

>>> cp -r /etc/skel /home/hadoop;chmod  -R go-rwx /home/hadoop

>>> ll hadoop/ -a

        drwx------.  2 root root  62 Sep  7 17:41 .

        drwxr-xr-x. 18 root root 236 Sep  7 17:41 ..

        -rw-------.  1 root root  18 Sep  7 17:41 .bash_logout

        -rw-------.  1 root root 193 Sep  7 17:41 .bash_profile

        -rw-------.  1 root root 231 Sep  7 17:41 .bashrc

5、修改/home/hadoop目录及其内部所有文件的属主为hadoop,属组为hadoop。

>>> ll -a hadoop/

        drwx------.  2 root root  62 Sep  7 17:41 .

        drwxr-xr-x. 18 root root 236 Sep  7 17:41 ..

        -rw-------.  1 root root  18 Sep  7 17:41 .bash_logout

        -rw-------.  1 root root 193 Sep  7 17:41 .bash_profile

        -rw-------.  1 root root 231 Sep  7 17:41 .bashrc

>>> chown -R hadoop.hadoop  hadoop

>>> ll -a hadoop/

        drwx------.  2 hadoop hadoop  62 Sep  7 17:41 .

        drwxr-xr-x. 18 root  root  236 Sep  7 17:41 ..

        -rw-------.  1 hadoop hadoop  18 Sep  7 17:41 .bash_logout

        -rw-------.  1 hadoop hadoop 193 Sep  7 17:41 .bash_profile

        -rw-------.  1 hadoop hadoop 231 Sep  7 17:41 .bashrc

6、显示/proc/meminfo文件中以大写或小写S开头的行;用两种方式;

>>> grep -E '^[sS]' /proc/meminfo 或  

>>>grep -i 's'   /proc/meminfo  或

>>> grep  '^[sS]'  /proc/meminfo

        SwapCached:            0 kB

        SwapTotal:      8257532 kB

        。。。。

>>> grep -E  '^(s|S)' /proc/meminfo 或

        SwapCached:            0 kB

        SwapTotal:      8257532 kB

        。。。。

7、显示/etc/passwd文件中其默认shell为非/sbin/nologin的用户;

 >>> grep -v '/sbin/nologin$' /etc/passwd | cut -d: -f1

        root

        sync

        shutdown

        halt

        appuser

        .......

        hadoop

8、显示/etc/passwd文件中其默认shell为/bin/bash的用户;

>>>grep '/bin/bash$' /etc/passwd | cut -d: -f1

        root

        appuser

        zabbix

        .....

        hadoop

9、找出/etc/passwd文件中的一位数或两位数;

>>>grep -Eo '\<[0-9]{1,2}\>' /etc/passwd

0

0

1

1

2

2

3

4

4

7

5

0

6

0

7

0

8

12

11

0

12

14

50

99

99

81

81

89

89

74

74

32

32

72

72

38

38

48

48

27

27

10、显示/etc/grub2.cfg中以至少一个空白字符开头的行;

>>>grep -E '^[[:space:]]{1,}' /etc/grub2.cfg

11、显示/etc/rc.d/rc.sysinit文件中以#开头,后面跟至少一个空白字符,而后又有至少一个非空白字符的行;

>>>grep -E '^#[[:space:]]{1,}[^[:space:]]{1,}' /etc/grub2.cfg

12、打出netstat -tan命令执行结果中以‘LISTEN’,后或跟空白字符结尾的行;

>>> netstat -tan | grep -E "LISTEN[[:space:]]?"

>>>netstat -tan | grep "LISTEN[[:space:]]\?"

13、添加用户bash, testbash, basher, nologin (此一个用户的shell为/sbin/nologin),而后找出当前系统上其用户名和默认shell相同的用户的信息;

>>>grep -E '^([^:]{1,}\>).*\1$' /etc/passwd

相关文章

网友评论

      本文标题:用户组和权限示例

      本文链接:https://www.haomeiwen.com/subject/tomcgftx.html