用户管理、组管理、权限管理、文本处理工具应用示例
-
1.复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其他用户均没有任何访问权限
[root@localhost ~]# cp -a /etc/skel/ /home/tuser1/ [root@localhost ~]# chmod -R go= /home/tuser1 [root@localhost home]# ls -l total 4 drwx------. 3 archlinux archlinux 78 Jul 1 20:04 archlinux drwx------. 14 njy njy 4096 Jul 16 05:13 njy drwx------. 3 root root 78 Jul 9 05:32 tuser1
-
2.编辑/etc/group文件,添加组hadoop
[root@localhost ~]# vim /etc/group [root@localhost ~]# echo "hadoop:x:1003:" >> /etc/group [root@localhost ~]# cat /etc/group njy:x:1000: gentoo:x:1001:archlinux archlinux:x:1002:njy hadoop:x:1003:
-
3.手动编辑/etc/passwd文件新增一行,添加用户hadoop,其基本组ID为hadoop组的id号,其家目录为/home/hadoop
[root@localhost ~]# vim /etc/passwd [root@localhost ~]# echo "hadoop:x:1002:1003:hadoop:/home/hadoop:/bin/bash" >> /etc/passwd [root@localhost ~]# cat /etc/passwd njy:x:1000:1000:centos1:/home/njy:/bin/bash archlinux:x:1001:1002::/home/archlinux:/bin/bash hadoop:x:1002:1003:hadoop:/home/hadoop:/bin/bash
-
4.复制/etc/skel目录为/home/hadoop,要求修改hadoop目录的属组和其他用户没有任何访问权限
[root@localhost home]# cp -a /etc/skel/ /home/hadoop/ [root@localhost home]# chmod -R go= /home/hadoop [root@localhost home]# ls -l total 4 drwx------. 3 archlinux archlinux 78 Jul 1 20:04 archlinux drwx------. 3 root root 78 Jul 9 05:32 hadoop drwx------. 14 njy njy 4096 Jul 16 05:13 njy drwx------. 3 root root 78 Jul 9 05:32 tuser1
-
5.修改/home/hadoop目录及其内部所有文件的属主为hadoop,属组为hadoop
[root@localhost home]# chown -R hadoop:hadoop hadoop [root@localhost home]# ls -l total 4 drwx------. 3 archlinux archlinux 78 Jul 1 20:04 archlinux drwx------. 3 hadoop hadoop 78 Jul 9 05:32 hadoop drwx------. 14 njy njy 4096 Jul 16 05:13 njy drwx------. 3 root root 78 Jul 9 05:32 tuser1
-
6.显示/proc/meminfo文件中以大写或小写S开头的行;用两种方式
[root@localhost home]# cat /proc/meminfo |grep "^[sS]" SwapCached: 0 kB SwapTotal: 2098172 kB SwapFree: 2098172 kB Shmem: 7300 kB Slab: 114724 kB SReclaimable: 62128 kB SUnreclaim: 52596 kB [root@localhost home]# cat /proc/meminfo |grep -i "^s" SwapCached: 0 kB SwapTotal: 2098172 kB SwapFree: 2098172 kB Shmem: 7300 kB Slab: 114724 kB SReclaimable: 62128 kB SUnreclaim: 52596 kB
-
7.显示/etc/passwd文件中其默认的shell为非/sbin/nologin的用户
[root@localhost home]# cat /etc/passwd|grep -v "/sbin/nologin$"|cut -d: -f1 root sync shutdown halt njy archlinux hadoop
-
8.显示/etc/passwd文件中其默认的shell为/bin/bash的用户
[root@localhost home]# cat /etc/passwd|grep "/bin/bash$"|cut -d: -f1 root njy archlinux hadoop
-
9.找出/etc/passwd文件中的一位数或者两位数
[root@localhost home]# cat /etc/passwd|grep -o -E "[[:digit:]]{1,2}"
-
10.显示/boot/grub/grub.conf中至少一个空白字符开头的行
[root@localhost home]# cat /boot/grub/grub.conf |grep "^[[:space:]]\+"
-
11.显示/etc/rc.d/rc.sysinit文件中以#开头,后面至少跟一个空白字符,而后又至少一个非空白字符的行
[root@localhost home]# cat /etc/rc.d/rc.sysinit|grep "^#[[:space:]]\+[^[:space:]]\+"
-
12.打出netstat -tan命令执行结果中以‘LISTEN’,后跟空白字符结尾的行
[root@localhost home]# netstat -tan|grep "LISTEN.*[[:space:]]\+$" tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN tcp6 0 0 :::111 :::* LISTEN tcp6 0 0 :::22 :::* LISTEN tcp6 0 0 ::1:631 :::* LISTEN tcp6 0 0 ::1:25 :::* LISTEN
-
13.添加用户bash,testbash,basher,nologin(此一个用户的shell为/sbin/nologin),而后找出当前系统上其用户名和默认shell相同的用户信息
[root@localhost home]# useradd bash [root@localhost home]# useradd testbash [root@localhost home]# useradd basher [root@localhost home]# useradd -s /sbin/nologin nologin [root@localhost home]# cat /etc/passwd|grep -E "^([[:alpha:]]+\>).*\1$" sync:x:5:0:sync:/sbin:/bin/sync shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown halt:x:7:0:halt:/sbin:/sbin/halt bash:x:1003:1004::/home/bash:/bin/bash nologin:x:1006:1007::/home/nologin:/sbin/nologin
原创文章,作者:N27_xiaoni,如若转载,请注明出处:http://www.178linux.com/82365
评论列表(1条)
赞,总结的不错,也没有出现错误,可见是用了心的,继续加油~