1、复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其它用户均没有任何访问权限。
[root@localhost ~]# cp -r /etc/skel /home/tuser1
[root@localhost ~]# chmod 700 /home/tuser1 -R
[root@localhost ~]# ls -ld /home/tuser1/
drwx——. 3 root root 78 Jun 3 22:05 /home/tuser1/
[root@localhost ~]# ls -al /home/tuser1
total 12
drwx——. 3 root root 78 Jun 3 22:05 .
drwxr-xr-x. 9 root root 112 Jun 3 22:05 ..
-rwx——. 1 root root 18 Jun 3 22:05 .bash_logout
-rwx——. 1 root root 193 Jun 3 22:05 .bash_profile
-rwx——. 1 root root 231 Jun 3 22:05 .bashrc
drwx——. 4 root root 39 Jun 3 22:05 .mozilla
[root@localhost ~]#
2、编辑/etc/group文件,添加组hadoop。
[root@localhost ~]# vim /etc/group
# 在打开的文件中最后编辑添加一行
hadoop:x:5216:
#组hadoop添加成功
[root@localhost ~]# groupadd hadoop
3、手动编辑/etc/passwd文件新增一行,添加用户hadoop,其基本组ID为hadoop组的id号;其家目录为/home/hadoop。
[root@localhost ~]# vim /etc/passwd
#在打开的文件最后编辑新增一行
hadoop:x:5216:5216::/home/hadoop:/bin/bash
#新用户hadoop添加成功
4、复制/etc/skel目录为/home/hadoop,要求修改hadoop目录的属组和其它用户没有任何访问权限。
[root@localhost ~]# cp -r /etc/skel /home/hadoop
[root@localhost ~]# chmod 700 /home/hadoop -R
[root@localhost ~]# ls -la /home/hadoop/
total 12
drwx——. 3 root root 78 Jun 3 22:16 .
drwxr-xr-x. 10 root root 126 Jun 3 22:16 ..
-rwx——. 1 root root 18 Jun 3 22:16 .bash_logout
-rwx——. 1 root root 193 Jun 3 22:16 .bash_profile
-rwx——. 1 root root 231 Jun 3 22:16 .bashrc
drwx——. 4 root root 39 Jun 3 22:16 .mozilla
5、修改/home/hadoop目录及其内部所有文件的属主为hadoop,属组为hadoop。
[root@localhost ~]# chown hadoop:hadoop /home/hadoop -R
[root@localhost ~]# ls -al /home/hadoop
total 12
drwx——. 3 root root 78 Jun 3 22:16 .
drwxr-xr-x. 10 root root 126 Jun 3 22:16 ..
-rwx——. 1 root root 18 Jun 3 22:16 .bash_logout
-rwx——. 1 root root 193 Jun 3 22:16 .bash_profile
-rwx——. 1 root root 231 Jun 3 22:16 .bashrc
drwx——. 4 root root 39 Jun 3 22:16 .mozilla
6、显示/proc/meminfo文件中以大写或小写S开头的行;用两种方式;
[root@localhost ~]# grep -i “^[s]” /proc/meminfo
SwapCached: 60 kB
SwapTotal: 2097148 kB
SwapFree: 2093328 kB
Shmem: 7260 kB
Slab: 125012 kB
SReclaimable: 60684 kB
SUnreclaim: 64328 kB
[root@localhost ~]# grep -E “^[sS]” /proc/meminfo
SwapCached: 60 kB
SwapTotal: 2097148 kB
SwapFree: 2093328 kB
Shmem: 7260 kB
Slab: 125012 kB
SReclaimable: 60684 kB
SUnreclaim: 64328 kB
7、显示/etc/passwd文件中其默认shell为非/sbin/nologin的用户;
[root@localhost ~]# grep -E -v “/sbin/nologin$” /etc/passwd | cut -d: -f1
root
sync
shutdown
halt
gentoo
liulian
user3
mageia
8、显示/etc/passwd文件中其默认shell为/bin/bash的用户;
[root@localhost ~]# grep -E “/bin/bash$” /etc/passwd | cut -d: -f1
root
gentoo
liulian
user3
mageia
9、找出/etc/passwd文件中的一位数或两位数;
[root@localhost ~]# 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
32
32
38
38
27
27
59
59
42
42
29
29
89
89
74
74
72
72
[root@localhost ~]# grep -o “\<[[:digit:]]\{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
32
32
38
38
27
27
59
59
42
42
29
29
89
89
74
74
72
72
10、显示/boot/grub/grub.conf中以至少一个空白字符开头的行;
[root@localhost ~]# grep -E “^[[:space:]]+.*” /boot/grub/grub.conf
grep: /boot/grub/grub.conf: No such file or directory
11、显示/etc/rc.d/rc.sysinit文件中以#开头,后面跟至少一个空白字符,而后又有至少一个非空白字符的行;
[root@localhost ~]# grep -E “^#[[:space:]]+[^[:space:]]+” /etc/rc.d/rc.sysinit
grep: /etc/rc.d/rc.sysinit: No such file or directory
12、打出netstat -tan命令执行结果中以‘LISTEN’,后或跟空白字符结尾的行;
[root@localhost ~]# 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
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 ~]# useradd bash
[root@localhost ~]# useradd testbash
[root@localhost ~]# useradd basher
[root@localhost ~]# useradd -s /sbin/nologin nologin
#查看是否添加成功
[root@localhost ~]# cat /etc/passwd
[#/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
systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
polkitd:x:999:997:User for polkitd:/:/sbin/nologin
colord:x:998:996:User for colord:/var/lib/colord:/sbin/nologin
abrt:x:173:173::/etc/abrt:/sbin/nologin
libstoragemgmt:x:997:994:daemon account for libstoragemgmt:/var/run/lsm:/sbin/nologin
rpc:x:32:32:Rpcbind Daemon:/var/lib/rpcbind:/sbin/nologin
setroubleshoot:x:996:993::/var/lib/setroubleshoot:/sbin/nologin
rtkit:x:172:172:RealtimeKit:/proc:/sbin/nologin
pulse:x:171:171:PulseAudio System Daemon:/var/run/pulse:/sbin/nologin
ntp:x:38:38::/etc/ntp:/sbin/nologin
chrony:x:995:990::/var/lib/chrony:/sbin/nologin
mysql:x:27:27:MariaDB Server:/var/lib/mysql:/sbin/nologin
tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin
geoclue:x:994:989:User for geoclue:/var/lib/geoclue:/sbin/nologin
sssd:x:993:988:User for sssd:/:/sbin/nologin
gdm:x:42:42::/var/lib/gdm:/sbin/nologin
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin
gentoo:x:1000:1000::/home/gentoo:/bin/bash
liulian:x:1001:1001::/home/liulian:/bin/bash
user3:x:1002:1002::/home/user3:/bin/bash
mageia:x:100:2017::/home/linux:/bin/bash
bash:x:1003:1003::/home/bash:/bin/bash
testbash:x:1004:1004::/home/testbash:/bin/bash
basher:x:1005:1005::/home/basher:/bin/bash
nologin:x:1006:1006::/home/nologin:/sbin/nologin
[root@localhost ~]# grep -E “^([[: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:1003:1003::/home/bash:/bin/bash
nologin:x:1006:1006::/home/nologin:/sbin/nologin
[root@localhost ~]#
本文来自投稿,不代表Linux运维部落立场,如若转载,请注明出处:http://www.178linux.com/100295