第四周博客作业了,感觉前面的有好多都忘掉了,但是没有时间补以前的啊……好郁闷,幸好今天周五,明天又是圣诞节,从马云爸爸买了一颗圣诞树,今晚回家装上
1. 复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其他用户均没有任何访问权限
[root@dhcp-10-129-6-166 ~]# install -d -m u=rwx,go= /etc/skel /home/tuser1;ll -d /home/tuser1 drwx------. 2 root root 6 12月 23 14:09 /home/tuser1 [root@dhcp-10-129-6-166 ~]#
2. 编辑/etc/group文件,添加组hadoop
[root@dhcp-10-129-6-166 home]# echo "hadoop:x:3100:" >> /etc/group [root@dhcp-10-129-6-166 home]# tail -1 /etc/group hadoop:x:3100: [root@dhcp-10-129-6-166 home]#
3. 手动编辑/etc/passwd文件新增一行,添加用户hadoop,,其基本组ID为hadoop组的ID号,其家目录为/home/hadoop
[root@dhcp-10-129-6-166 home]# tail /etc/passwd mysql:x:996:994::/home/mysql:/bin/nologin mariadb:x:995:993::/home/mariadb:/sbin/nologin gentoo:x:2004:2004::/users/gentoo:/bin/bash fedora:x:2005:2005::/users/fedora:/bin/bash centos:x:2006:2006::/home/centos:/bin/bash bash:x:2007:2007::/home/bash:/bin/bash testbash:x:2008:2008::/home/testbash:/bin/bash basher:x:2009:2009::/home/basher:/bin/bash nologin:x:2010:2010::/home/nologin:/sbin/nologin Bash:x:3001:3001::/home/Bash:/bin/bash [root@dhcp-10-129-6-166 home]# echo "hadoop:x:3100:3100::/home/hadoop:/bin/bash" >> /etc/passwd [root@dhcp-10-129-6-166 home]# tail -1 /etc/passwd hadoop:x:3100:3100::/home/hadoop:/bin/bash
4. 复制/etc/skel目录为/home/hadoop, 要求修改hadoop目录的属组和其他用户没有任何访问权限
[root@dhcp-10-129-6-166 home]# install -d -m go-rwx /etc/skel /home/hadoop [root@dhcp-10-129-6-166 home]# ll -d /home/hadoop drwx------. 2 root root 6 12月 23 13:54 /home/hadoop [root@dhcp-10-129-6-166 home]#
5. 修改/home/hadoop目录及其内部所有文件的属主为hadoop,属组为hadoop
[root@dhcp-10-129-6-166 home]# ll /home/hadoop 总用量 0 -rw-r--r--. 1 root root 0 12月 23 13:36 file1 -rw-r--r--. 1 root root 0 12月 23 13:36 file2 -rw-r--r--. 1 root root 0 12月 23 13:36 file3 -rw-r--r--. 1 root root 0 12月 23 13:36 file4 [root@dhcp-10-129-6-166 home]# chown -R hadoop:hadoop /home/hadoop;ll -r /home/hadoop 总用量 0 -rw-r--r--. 1 hadoop hadoop 0 12月 23 13:36 file4 -rw-r--r--. 1 hadoop hadoop 0 12月 23 13:36 file3 -rw-r--r--. 1 hadoop hadoop 0 12月 23 13:36 file2 -rw-r--r--. 1 hadoop hadoop 0 12月 23 13:36 file1 [root@dhcp-10-129-6-166 home]#
6. 显示/proc/meminfo文件中以大写或小写S开头的行,用两种方式
[root@dhcp-10-129-6-166 ~]# grep "^[sS]" /proc/meminfo SwapCached: 0 kB SwapTotal: 2097148 kB SwapFree: 2097148 kB Shmem: 13104 kB Slab: 73684 kB SReclaimable: 36116 kB SUnreclaim: 37568 kB [root@dhcp-10-129-6-166 ~]# grep "^(s|S)" /proc/meminfo [root@dhcp-10-129-6-166 ~]# grep -E "^(s|S)" /proc/meminfo SwapCached: 0 kB SwapTotal: 2097148 kB SwapFree: 2097148 kB Shmem: 13104 kB Slab: 73684 kB SReclaimable: 36116 kB SUnreclaim: 37568 kB
7. 显示/etc/passwd文件中其默认shell为非/sbin/nologin的用户
[root@dhcp-10-129-6-166 system]# grep -v "/sbin/nologin$" /etc/passwd root:x:0:0:root:/root:/bin/bash sync:x:5:0:sync:/sbin:/bin/sync shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown halt:x:7:0:halt:/sbin:/sbin/halt mageia:x:1100:1100::/home/linux:/bin/bash slackware:x:2002:2016::/home/slackware:/bin/bash openstack:x:2003:2020::/home/openstack:/bin/bash mysql:x:996:994::/home/mysql:/bin/nologin gentoo:x:2004:2004::/users/gentoo:/bin/bash fedora:x:2005:2005::/users/fedora:/bin/bash centos:x:2006:2006::/home/centos:/bin/bash bash:x:2007:2007::/home/bash:/bin/bash testbash:x:2008:2008::/home/testbash:/bin/bash basher:x:2009:2009::/home/basher:/bin/bash hadoop:x:3000:3000::/home/hadoop:/bin/bash Bash:x:3001:3001::/home/Bash:/bin/bash
8. 显示/etc/passwd文件中其默认shell为/bin/bash的用户
[root@dhcp-10-129-6-166 ~]# grep "/bin/bash$" /etc/passwd root:x:0:0:root:/root:/bin/bash mageia:x:1100:1100::/home/linux:/bin/bash slackware:x:2002:2016::/home/slackware:/bin/bash openstack:x:2003:2020::/home/openstack:/bin/bash gentoo:x:2004:2004::/users/gentoo:/bin/bash fedora:x:2005:2005::/users/fedora:/bin/bash centos:x:2006:2006::/home/centos:/bin/bash bash:x:2007:2007::/home/bash:/bin/bash testbash:x:2008:2008::/home/testbash:/bin/bash basher:x:2009:2009::/home/basher:/bin/bash hadoop:x:3000:3000::/home/hadoop:/bin/bash
9. 找出/etc/passwd文件中的一位数或两位数
[root@dhcp-10-129-6-166 ~]# grep -E -o "\<[0-9]\>|\<[0-9][0-9]\>" /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 59 59 89 89 74 74 [root@dhcp-10-129-6-166 ~]#
10. 显示/boot/grub/grub.conf中以至少一个空白字符开头的行
[root@dhcp-10-129-6-166 ~]# grep "^[[:space:]]\+" /boot/grub2/grub.cfg load_env set default="${next_entry}" set next_entry= save_env next_entry set boot_once=true set default="${saved_entry}" menuentry_id_option="--id" menuentry_id_option="" set saved_entry="${prev_saved_entry}" save_env saved_entry set prev_saved_entry= save_env prev_saved_entry set boot_once=true if [ -z "${boot_once}" ]; then saved_entry="${chosen}" save_env saved_entry fi if [ x$feature_all_video_module = xy ]; then insmod all_video ...
11. 显示/etc/rc.d/rc.sysinit文件中以#开头,后面跟至少一个空白字符,而后有至少一个非空白字符的行
[root@dhcp-10-129-6-166 ~]# grep "^#[[:space:]][^[:space:]]" /etc/rc.d/rc.sysinit
12. 打出netstat -tan命令执行结果中以'LISTEN',后或根空白字符结尾的行
[root@dhcp-10-129-6-166 system]# netstat -tan | grep "\<LISTEN\>[[:space:]]\+$" tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN tcp6 0 0 :::22 :::* LISTEN tcp6 0 0 ::1:25 :::* LISTEN
13. 添加用户Bash,testbash, basher, nologin(此一个用户的shell为/sbin/nologin), 而后找出当前系统上其用户名和默认shell相同的用户的信息
[root@dhcp-10-129-6-166 system]# grep -E "^(\<[^:]+\>).*\<\1\>$" /etc/passwd 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:2007:2007::/home/bash:/bin/bash nologin:x:2010:2010::/home/nologin:/sbin/nologin
14. 显示/proc/meminfo文件中以大写或小写S开头的行,用三种方式
[root@dhcp-10-129-6-166 system]# grep "^[sS]" /proc/meminfo SwapCached: 0 kB SwapTotal: 2097148 kB SwapFree: 2097148 kB Shmem: 13104 kB Slab: 73876 kB SReclaimable: 36340 kB SUnreclaim: 37536 kB [root@dhcp-10-129-6-166 system]# grep -E "^(s|S)" /proc/meminfo SwapCached: 0 kB SwapTotal: 2097148 kB SwapFree: 2097148 kB Shmem: 13104 kB Slab: 73876 kB SReclaimable: 36340 kB SUnreclaim: 37536 kB [root@dhcp-10-129-6-166 system]# grep -i "^s" /proc/meminfo SwapCached: 0 kB SwapTotal: 2097148 kB SwapFree: 2097148 kB Shmem: 13104 kB Slab: 73876 kB SReclaimable: 36340 kB SUnreclaim: 37536 kB
15. 显示/etc/passwd文件中其默认shell为非/sbin/nologin的用户
[root@dhcp-10-129-6-166 system]# grep "/sbin/nologin$" /etc/passwd bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin adm:x:3:4:adm:/var/adm:/sbin/nologin lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin mail:x:8:12:mail:/var/spool/mail:/sbin/nologin operator:x:11:0:operator:/root:/sbin/nologin games:x:12:100:games:/usr/games:/sbin/nologin ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin nobody:x:99:99:Nobody:/:/sbin/nologin avahi-autoipd:x:170:170:Avahi IPv4LL Stack:/var/lib/avahi-autoipd:/sbin/nologin systemd-bus-proxy:x:999:997:systemd Bus Proxy:/:/sbin/nologin systemd-network:x:998:996:systemd Network Management:/:/sbin/nologin dbus:x:81:81:System message bus:/:/sbin/nologin polkitd:x:997:995:User for polkitd:/:/sbin/nologin tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin postfix:x:89:89::/var/spool/postfix:/sbin/nologin sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin mariadb:x:995:993::/home/mariadb:/sbin/nologin nologin:x:2010:2010::/home/nologin:/sbin/nologin
16. 显示/etc/passwd文件中其默认shell为/bin/bash的用户
[root@dhcp-10-129-6-166 system]# grep "/bin/bash$" /etc/passwd root:x:0:0:root:/root:/bin/bash mageia:x:1100:1100::/home/linux:/bin/bash slackware:x:2002:2016::/home/slackware:/bin/bash openstack:x:2003:2020::/home/openstack:/bin/bash gentoo:x:2004:2004::/users/gentoo:/bin/bash fedora:x:2005:2005::/users/fedora:/bin/bash centos:x:2006:2006::/home/centos:/bin/bash bash:x:2007:2007::/home/bash:/bin/bash testbash:x:2008:2008::/home/testbash:/bin/bash basher:x:2009:2009::/home/basher:/bin/bash hadoop:x:3000:3000::/home/hadoop:/bin/bash Bash:x:3001:3001::/home/Bash:/bin/bash
17. 找出/etc/passwd文件中的一位数或两位数
[root@dhcp-10-129-6-166 ~]# grep -E -o "\<[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 59 59 89 89 74 74 [root@dhcp-10-129-6-166 ~]#
原创文章,作者:JL,如若转载,请注明出处:http://www.178linux.com/64267