Quantcast
Channel: CodeSection,代码区,Linux操作系统:Ubuntu_Centos_Debian - CodeSec
Viewing all articles
Browse latest Browse all 11063

第四周作业

$
0
0

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

[root@loalhost ~]# (umask 077; cp -r /etc/skel /home/user1)

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

[root@localhost ~]# sed -i '$a\hadoop:x:500' /etc/group
[root@localhost ~]# tail -5 /etc/group
mongodb:x:503:
pns:x:504:
xiaoxin:x:505:
XIAOXIN:x:506:
hadoop:x:500

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

[root@localhost ~]# sed -i '$a\hadoop:x:500:500::/home/hadoop:/bin/bash' /etc/passwd
[root@localhost ~]# tail -1 /etc/group
hadoop:x:500:500::/home/hadoop:/bin/bash

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

[root@localhost ~]# (umask 077; cp -r /etc/skel /home/hadoop)

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

[root@localhost ~]# chown -r hadoop /home/hadoop

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

[root@localhost ~]# grep \[sS\] /proc/meminfo
Buffers: 172756 kB
SwapCached: 3792 kB
SwapTotal: 8327160 kB
SwapFree: 8192284 kB
AnonPages: 10195868 kB
Shmem: 7096 kB
Slab: 585472 kB
SReclaimable: 537136 kB
SUnreclaim: 48336 kB
KernelStack: 12280 kB
PageTables: 41752 kB
NFS_Unstable: 0 kB
Committed_AS: 25695728 kB
VmallocUsed: 173456 kB
AnonHugePages: 8472576 kB
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB

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

[root@localhost ~]# grep [^nologin]$ /etc/passwd
root:x:0:0:root:/root:/bin/bash
sync:x:5:0:sync:/sbin:/bin/sync

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

[root@localhost ~]# grep bash$ /etc/passwd
root:x:0:0:root:/root:/bin/bash
ricci:x:140:140:ricci daemon user:/var/lib/ricci:/bin/bash

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

[root@localhost ~]# grep -E --color "\<[0-9]{1,2}\>" /etc/passwd
root:x:0:0:root:/root:/bin/bash
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
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin

10、显示/boot/grub/grub.conf中以至少一个空白字符开头的行;

[root@localhost ~]# grep -E --color "^[[:space:]]+" /etc/grub.conf
root (hd0,0)
kernel /vmlinuz-2.6.32-358.el6.x86_64 ro root=UUID=ad5e4daa-0814-4b82-99c3-125cee3f3f76 rd_NO_LUKS rd_NO_LVM.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet
initrd /initramfs-2.6.32-358.el6.x86_64.img

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

[root@localhost ~]# grep -E --color "^#[[:space:]]+[a-z]+" /etc/rc.d/rc.sysinit
# mounted). Contrary to standard usage,
# filesystems are NOT unmounted in single user mode.
# let's dump the syslog ring somewhere so we can find it later
# create the crash indicator flag to warn on crashes, offer fsck with timeout

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

[root@localhost ~]# netstat -nta|grep -E 'LISTEN[[:space:]]+$'
tcp 0 0 0.0.0.0:9003 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:15915 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:11211 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:40684 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:12812 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:3308 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:110 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:26926 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:143 0.0.0.0:* LISTEN

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

[root@localhost ~]# grep -E --color '^(\<[a-z]+\>).*\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:507:507::/home/bash:/bin/bash
nologin:x:510:510::/home/nologin:/sbin/nologin

Viewing all articles
Browse latest Browse all 11063

Trending Articles