Linux运维之路第四篇

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

[root@VM_0_6_centos ~]# cp -r /etc/skel /home/tuser1

[root@VM_0_6_centos ~]# chmod -R go-rwx /home/tuser1/

[root@VM_0_6_centos ~]# ll -a /home/tuser1/
total 20
drwx——   2 root root 4096 Sep 20 21:17 .
drwxr-xr-x. 16 root root 4096 Sep 20 21:17 ..
-rw——-   1 root root   18 Sep 20 21:17 .bash_logout
-rw——-   1 root root  193 Sep 20 21:17 .bash_profile
-rw——-   1 root root  231 Sep 20 21:17 .bashrc
 

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

[root@VM_0_6_centos ~]# nano /etc/group
[root@VM_0_6_centos ~]# tail -1 /etc/group
hadoop:x:5003
 

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

[root@VM_0_6_centos ~]# nano /etc/passwd
[root@VM_0_6_centos ~]# tail -1 /etc/passwd
hadoop:x5003:5003::/home/hadoop:/bin/bash
 

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

[root@VM_0_6_centos ~]# cp -r /etc/skel /home/hadoop
[root@VM_0_6_centos ~]# chmod -R 700 /home/hadoop
[root@VM_0_6_centos ~]# ll -a /home/hadoop
total 24
drwx——   3 root root 4096 Sep 20 21:44 .
drwxr-xr-x. 17 root root 4096 Sep 20 21:42 ..
-rwx——   1 root root   18 Sep 20 21:42 .bash_logout
-rwx——   1 root root  193 Sep 20 21:42 .bash_profile
-rwx——   1 root root  231 Sep 20 21:42 .bashrc
drwx——   2 root root 4096 Sep 20 21:44 skel
 

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

[root@VM_0_6_centos ~]# chown -R hadoop:hadoop /home/hadoop
[root@VM_0_6_centos ~]# ls -a -l /home/hadoop
total 24
drwx——   3 hadoop hadoop 4096 Sep 20 21:44 .
drwxr-xr-x. 17 root   root   4096 Sep 20 21:42 ..
-rwx——   1 hadoop hadoop   18 Sep 20 21:42 .bash_logout
-rwx——   1 hadoop hadoop  193 Sep 20 21:42 .bash_profile
-rwx——   1 hadoop hadoop  231 Sep 20 21:42 .bashrc
drwx——   2 hadoop hadoop 4096 Sep 20 21:44 skel

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

[root@VM_0_6_centos ~]# grep -i '^s' /proc/meminfo
SwapCached:            0 kB
SwapTotal:             0 kB
SwapFree:              0 kB
Shmem:               480 kB
Slab:             117664 kB
SReclaimable:     107368 kB
SUnreclaim:        10296 kB

[root@VM_0_6_centos ~]# grep -E '^(s|S)' /proc/meminfo
SwapCached:            0 kB
SwapTotal:             0 kB
SwapFree:              0 kB
Shmem:               480 kB
Slab:             117576 kB
SReclaimable:     107368 kB
SUnreclaim:        10208 kB 
 

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

[root@VM_0_6_centos ~]#  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
syslog:x:996:994::/home/syslog:/bin/false
gentoo:x:1001:1001::/users/gentoo:/bin/bash
fedora:x:1002:1002::/users/fedora:/bin/bash
user1:x:1003:1003::/home/user1:/bin/bash
peter:x:1004:1004::/home/peter:/bin/bash
user3:x:1006:1006::/home/user3:/bin/bash
user4:x:1007:1007::/home/user4:/bin/bash
centos:x:1008:1008::/home/centos:/bin/bash
bash:x:1009:1009::/home/bash:/bin/bash
basher:x:1010:1010::/home/basher:/bin/bash
testbash:x:1011:1011::/home/testbash:/bin/bash
mageia:x:1100:1100::/home/linux:/bin/bash
slackware:x:2002:2016::/home/slackware:/bin/tcsh
hadoop:x:5003:5003::/home/hadoop:/bin/bash

 

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

[root@VM_0_6_centos ~]#  grep '/bin/bash$' /etc/passwd
root:x:0:0:root:/root:/bin/bash
gentoo:x:1001:1001::/users/gentoo:/bin/bash
fedora:x:1002:1002::/users/fedora:/bin/bash
user1:x:1003:1003::/home/user1:/bin/bash
peter:x:1004:1004::/home/peter:/bin/bash
user3:x:1006:1006::/home/user3:/bin/bash
user4:x:1007:1007::/home/user4:/bin/bash
centos:x:1008:1008::/home/centos:/bin/bash
bash:x:1009:1009::/home/bash:/bin/bash
basher:x:1010:1010::/home/basher:/bin/bash
testbash:x:1011:1011::/home/testbash:/bin/bash
mageia:x:1100:1100::/home/linux:/bin/bash
hadoop:x:5003:5003::/home/hadoop:/bin/bash

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

root@VM_0_6_centos ~]# grep -E '\<[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
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
dbus:x:81:81:System message bus:/:/sbin/nologin
rpc:x:32:32:Rpcbind Daemon:/var/lib/rpcbind:/sbin/nologin
ntp:x:38:38::/etc/ntp:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin

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

[root@VM_0_6_centos ~]# grep ‘^[[:space:]]\+' /boot/grub/grub.conf

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

[root@VM_0_6_centos ~]# grep -E ^#[[:space:]]+[^[:space:]]+ /etc/rc.d/rc.syssinit
 


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

[root@VM_0_6_centos ~]# netstat -tan |grep -E “LISTEN[[:space:]]+$"
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN     
tcp6       0      0 :::111                  :::*                    LISTEN     

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

[root@VM_0_6_centos ~]# 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
nobody:x:99:99:Nobody:/:/sbin/nologin
ntp:x:38:38::/etc/ntp:/sbin/nologin
bash:x:1009:1009::/home/bash:/bin/bash
basher:x:1010:1010::/home/basher:/bin/bash
nologin:x:1012:1012::/home/nologin:/sbin/nologin
hadoop:x:5003:5003::/home/hadoop:/bin/bash
 

 

 

 

原创文章,作者:斌斌,如若转载,请注明出处:http://www.178linux.com/124362

发表评论

登录后才能评论

This site uses Akismet to reduce spam. Learn how your comment data is processed.

联系我们

400-080-6560

在线咨询

工作时间:周一至周五,9:30-18:30,节假日同时也值班

QR code