马哥linux课后作业4
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了马哥linux课后作业4相关的知识,希望对你有一定的参考价值。
1、复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其它用户均没有任何访问权限。
[[email protected] home]# cp -r /etc/skel/ /home/tuser1
[[email protected] home]# chmod -R u-r,o-r tuser1/
[[email protected] home]# ll
total 40
drwx------. 2 bash bash 4096 Aug 13 12:01 bash
drwx------. 2 basher basher 4096 Aug 13 12:01 basher
drwx------. 2 mageia mageia 4096 Aug 14 01:14 linux
drwx------. 2 1005 distro 4096 Aug 14 01:12 mandriva
drwx------. 2 nologin nologin 4096 Aug 13 12:01 nologin
drwx------. 2 openstack clouds 4096 Aug 14 01:50 openstack
drwx------. 2 slackware distro 4096 Aug 14 01:24 slackware
drwx------. 2 testbash testbash 4096 Aug 13 12:01 testbash
d-wxr-x--x. 2 root root 4096 Aug 14 13:58 tuser1
drwx------. 2 zengzy zengzy 4096 Aug 13 08:28 zengzy
[[email protected] home]# su zengzy
[[email protected] home]$ cd /home/tuser1/
[[email protected] tuser1]$ ls
ls: cannot open directory .: Permission denied
2、编辑/etc/group文件,添加组hadoop。
[[email protected] home]# vim /etc/group
[email protected] home]# tail -n 5 /etc/group
admins:x:2018:slackware
clouds:x:2019:
nova:x:2020:openstack
mysql:x:498:
hadoop:x:499:
[[email protected] home]# echo ‘hadoop1:x:505:‘ >> /etc/group
[[email protected] home]# tail -n 1 /etc/group
hadoop1:x:505:
3、手动编辑/etc/passwd文件新增一行,添加用户hadoop,其基本组ID为hadoop组的id号;其家目录为/home/hadoop。
[[email protected] home]# vim /etc/passwd
hadoop:x:505:499::/home/hadoop:/bin/bash
[[email protected] home]# id hadoop
uid=505(hadoop) gid=499(hadoop) groups=499(hadoop)
[[email protected] home]# echo ‘hadoop1:x:506:505::/home/hadpood1:/bin/bash‘ >> /etc/passwd
[[email protected] home]# id hadoop1
uid=506(hadoop1) gid=505(hadoop1) groups=505(hadoop1)
4、复制/etc/skel目录为/home/hadoop,要求修改hadoop目录的属组和其它用户没有任何访问权限。
[[email protected] home]# cp -r /etc/skel /home/hadoop
[[email protected] home]# ll
total 44
drwx------. 2 bash bash 4096 Aug 13 12:01 bash
drwx------. 2 basher basher 4096 Aug 13 12:01 basher
drwxr-xr-x. 2 root root 4096 Aug 14 14:22 hadoop
drwx------. 2 mageia mageia 4096 Aug 14 01:14 linux
drwx------. 2 1005 distro 4096 Aug 14 01:12 mandriva
drwx------. 2 nologin nologin 4096 Aug 13 12:01 nologin
drwx------. 2 openstack clouds 4096 Aug 14 01:50 openstack
drwx------. 2 slackware distro 4096 Aug 14 01:24 slackware
drwx------. 2 testbash testbash 4096 Aug 13 12:01 testbash
d-wxr-x--x. 2 root root 4096 Aug 14 13:58 tuser1
drwx------. 2 zengzy zengzy 4096 Aug 13 08:28 zengzy
[[email protected] home]# chmod g-r,o-r hadoop/
[[email protected] home]# ll
total 44
drwx------. 2 bash bash 4096 Aug 13 12:01 bash
drwx------. 2 basher basher 4096 Aug 13 12:01 basher
drwx--x--x. 2 root root 4096 Aug 14 14:22 hadoop
drwx------. 2 mageia mageia 4096 Aug 14 01:14 linux
drwx------. 2 1005 distro 4096 Aug 14 01:12 mandriva
drwx------. 2 nologin nologin 4096 Aug 13 12:01 nologin
drwx------. 2 openstack clouds 4096 Aug 14 01:50 openstack
drwx------. 2 slackware distro 4096 Aug 14 01:24 slackware
drwx------. 2 testbash testbash 4096 Aug 13 12:01 testbash
d-wxr-x--x. 2 root root 4096 Aug 14 13:58 tuser1
drwx------. 2 zengzy zengzy 4096 Aug 13 08:28 zengzy
5、修改/home/hadoop目录及其内部所有文件的属主为hadoop,属组为hadoop。
[[email protected] home]# ll
total 44
drwx------. 2 bash bash 4096 Aug 13 12:01 bash
drwx------. 2 basher basher 4096 Aug 13 12:01 basher
drwx--x--x. 2 root root 4096 Aug 14 14:22 hadoop
drwx------. 2 mageia mageia 4096 Aug 14 01:14 linux
drwx------. 2 1005 distro 4096 Aug 14 01:12 mandriva
drwx------. 2 nologin nologin 4096 Aug 13 12:01 nologin
drwx------. 2 openstack clouds 4096 Aug 14 01:50 openstack
drwx------. 2 slackware distro 4096 Aug 14 01:24 slackware
drwx------. 2 testbash testbash 4096 Aug 13 12:01 testbash
d-wxr-x--x. 2 root root 4096 Aug 14 13:58 tuser1
drwx------. 2 zengzy zengzy 4096 Aug 13 08:28 zengzy
[[email protected] home]# chown -R hadoop:hadoop hadoop/
[[email protected] home]# ll
total 44
drwx------. 2 bash bash 4096 Aug 13 12:01 bash
drwx------. 2 basher basher 4096 Aug 13 12:01 basher
drwx--x--x. 2 hadoop hadoop 4096 Aug 14 14:22 hadoop
drwx------. 2 mageia mageia 4096 Aug 14 01:14 linux
drwx------. 2 1005 distro 4096 Aug 14 01:12 mandriva
drwx------. 2 nologin nologin 4096 Aug 13 12:01 nologin
drwx------. 2 openstack clouds 4096 Aug 14 01:50 openstack
drwx------. 2 slackware distro 4096 Aug 14 01:24 slackware
drwx------. 2 testbash testbash 4096 Aug 13 12:01 testbash
d-wxr-x--x. 2 root root 4096 Aug 14 13:58 tuser1
drwx------. 2 zengzy zengzy 4096 Aug 13 08:28 zengzy
6、显示/proc/meminfo文件中以大写或小写S开头的行;用两种方式;
[[email protected] home]# cat /proc/meminfo | grep "^[sS]"
SwapCached: 0 kB
SwapTotal: 2097148 kB
SwapFree: 2097148 kB
Shmem: 236 kB
Slab: 106148 kB
SReclaimable: 46064 kB
SUnreclaim: 60084 kB
[[email protected] home]# cat /proc/meminfo | grep -i "^s"
SwapCached: 0 kB
SwapTotal: 2097148 kB
SwapFree: 2097148 kB
Shmem: 236 kB
Slab: 106144 kB
SReclaimable: 46060 kB
SUnreclaim: 60084 kB
7、显示/etc/passw d文件中其默认shell为非/sbin/nologin的用户;
[[email protected] home]# cat /etc/passwd | grep -v "/sbin/nologin$" | cut -d: -f1
root
sync
shutdown
halt
zengzy
bash
basher
testbash
mageia
slackware
openstack
hadoop
hadoop1
8、显示/etc/passw d文件中其默认shell为/bin/bash的用户;
[[email protected] home]# cat /etc/passwd | grep "/bin/bash$" | cut -d: -f1
root
zengzy
bash
basher
testbash
mageia
openstack
hadoop
hadoop1
9、找出/etc/passw d文件中的一位数或两位数;
[[email protected] home]# egrep "\<[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
uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
gopher:x:13:30:gopher:/var/gopher:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
vcsa:x:69:69:virtual console memory owner:/dev:/sbin/nologin
saslauth:x:499:76:Saslauthd user:/var/empty/saslauth:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
[[email protected] home]# grep --color=auto "\<[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
uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
gopher:x:13:30:gopher:/var/gopher:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
vcsa:x:69:69:virtual console memory owner:/dev:/sbin/nologin
saslauth:x:499:76:Saslauthd user:/var/empty/saslauth:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
10、显示/boot/grub/grub.conf中以至少一个空白字符开头的行;
[[email protected] home]# grep "^[[:space:]]\+" /boot/grub/grub.conf
root (hd0,0)
kernel /vmlinuz-2.6.32-642.4.2.el6.x86_64 ro root=UUID=b175aee5-62ee-4625-8aac-f3c455133efa rd_NO_LUKS rd_NO_LVM LANG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet
initrd /initramfs-2.6.32-642.4.2.el6.x86_64.img
root (hd0,0)
kernel /vmlinuz-2.6.32-642.el6.x86_64 ro root=UUID=b175aee5-62ee-4625-8aac-f3c455133efa rd_NO_LUKS rd_NO_LVM LANG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet
initrd /initramfs-2.6.32-642.el6.x86_64.img
11、显示/etc/rc.d/rc.sysinit文件中以#开头,后面跟至少一个空白字符,而后又有至少一个非空白字符的行;
[[email protected] home]# grep "^#[[:space:]]\+[^[:space:]]\+" /etc/rc.d/rc.sysinit
12、打出netstat -tan命令执行结果中以‘LISTEN’,后或跟空白字符结尾的行;
[[email protected] home]# netstat -tan | egrep "LISTTEN|[[:space:]]$"
Proto Recv-Q Send-Q Local Address Foreign Address State
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
tcp 0 64 192.168.2.105:22 192.168.2.106:12341 ESTABLISHED
tcp 0 0 192.168.2.105:22 192.168.2.106:3099 ESTABLISHED
tcp 0 0 :::22 :::* LISTEN
tcp 0 0 ::1:25 :::* LISTEN
13、添加用户bash, testbash, basher, nologin (此一个用户的shell为/sbin/nologin),而后找出当前系统上其用户名和默认shell相同的用户的信息;
[[email protected] home]# useradd bash
[[email protected] home]# useradd tetstbash
[[email protected] home]# useradd basher
[[email protected] home]# useradd -s /sbin/nologin nologin
[[email protected] home]# grep --color=auto "^\([[:alnum:]]\+\>\).*\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:501:501::/home/bash:/bin/bash
nologin:x:504:504::/home/nologin:/sbin/nologin
本文出自 “给自己充电” 博客,请务必保留此出处http://zengzeyang.blog.51cto.com/6129531/1842811
以上是关于马哥linux课后作业4的主要内容,如果未能解决你的问题,请参考以下文章