用户目录权限管理.手动添加用户.截取用户信息

  1. 复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其它用户均没有任何访问权限。
[root@db146 ~]# cp -R /etc/skel /home/tuser1
[root@db146 tuser1]# chmod -R go=- /home/tuser1
[root@db146 tuser1]# ll
总用量 0
-rw-------. 1 root root 0 12月 23 23:30 11.txt
  1. 编辑/etc/group文件,添加组hadoop。
[root@db146 tuser1]# vim /etc/group
hadoop:x:2000:
[root@db146 tuser1]# id test
uid=2003(test) gid=2000(hadoop) 组=2000(hadoop)
  1. 手动编辑/etc/passwd文件新增一行,添加用户hadoop,其基本组ID为hadoop组的id号;其家目录为/home/hadoop。
    [root@db146 tuser1]# vi /etc/passwd
hadoop:x:1101:2000::/home/hadoop:/bin/bash
  1. 复制/etc/skel目录为/home/hadoop,要求修改hadoop目录的属组和其它用户没有任何访问权限。
[root@db146 tuser1]# cp -R /etc/skel /home/hadoop && chmod go=- /home/hadoop
  1. 修改/home/hadoop目录及其内部所有文件的属主为hadoop,属组为hadoop。
[root@db146 tuser1]# chown hadoop:hadoop /home/hadoop
[root@db146 tuser1]# ll /home/|grep hadoop
drwx------. 2 hadoop    hadoop 59 12月 24 00:08 hadoop
  1. 显示/proc/meminfo文件中以大写或小写S开头的行;用两种方式;
[root@db146 tuser1]# cat /proc/meminfo |grep '^[Ss]'
SwapCached:            0 kB
SwapTotal:       1048572 kB
SwapFree:        1048572 kB
Shmem:              6852 kB
Slab:              56016 kB
SReclaimable:      19760 kB
SUnreclaim:        36256 kB
[root@db146 tuser1]# cat /proc/meminfo |grep  -i '^s'
SwapCached:            0 kB
SwapTotal:       1048572 kB
SwapFree:        1048572 kB
Shmem:              6852 kB
Slab:              56036 kB
SReclaimable:      19760 kB
SUnreclaim:        36276 kB
  1. 显示/etc/passwd文件中其默认shell为非/sbin/nologin的用户;
[root@db146 tuser1]# cat /etc/passwd|grep -v '/sbin/nologin'|cut -d ':' -f1
root
sync
shutdown
halt
11
user2
user3
mageia
slackware
test
hadoop
  1. 显示/etc/passwd文件中其默认shell为/bin/bash的用户;
[root@db146 tuser1]# cat /etc/passwd|grep  '/bin/bash'|cut -d ':' -f1
root
11
user2
user3
mageia
test
hadoop
  1. 找出/etc/passwd文件中的一位数或两位数;
[root@db146 tuser1]# cat /etc/passwd |grep  "<[0-9]{1,2}>"
[root@db146 tuser1]# cat /etc/passwd | grep -E "<[0-9]{1,2}>"
  1. 显示/boot/grub/grub.conf中以至少一个空白字符开头的行;
[root@db146 tuser1]# cat /boot/grub/grub.conf |grep '^ '
  1. 显示/etc/rc.d/rc.sysinit文件中以#开头,后面跟至少一个空白字符,而后又有至少一个非空白字符的行;
[root@db146 tuser1]# cat /lgp/rc.sysinit |grep "^#[[:space:]]+[^[:space:]]+"
  1. 打出netstat -tan命令执行结果中以‘LISTEN’,后或跟空白字符结尾的行;
[root@db146 tuser1]# 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     
tcp        0      0 127.0.0.1:199           0.0.0.0:*               LISTEN     
tcp6       0      0 :::22                   :::*                    LISTEN     
tcp6       0      0 ::1:25                  :::*                    LISTEN  
  1. 添加用户bash, testbash, basher, nologin (此一个用户的shell为/sbin/nologin),而后找出当前系统上其用户名和默认shell相同的用户的信息;"
[root@db146 tuser1]# useradd bash
[root@db146 tuser1]# useradd testbash
[root@db146 tuser1]# useradd basher
[root@db146 tuser1]# useradd -s /sbin/nologin nologin
[root@db146 tuser1]# grep  "^([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:2004:2004::/home/bash:/bin/bash
nologin:x:2007:2007::/home/nologin:/sbin/nologin
原文地址:https://www.cnblogs.com/kangfeng/p/8094014.html