Linux基本内容介绍(4)-- 用户和组的管理,权限设定和正则表达式的练习

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

    [root@localhost home]# chmod -R 700 tuser1/
    [root@localhost home]# ls -ld tuser1/
    drwx------. 2 gentoo gentoo 4096 Sep  6 16:53 tuser1/
    [root@localhost home]# ls -R tuser1/
    tuser1/:
    test1
    [root@localhost home]# 
    

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

    [root@localhost ~]# tail -1 /etc/gshadow && tail -1 /etc/group
    hadoop:!::
    hadoop:x:5003:

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

    [root@localhost ~]# echo "hadoop:x:600:5004::/home/hadoop:/bin/bash" >> /etc/passwd
    [root@localhost ~]# echo "hadoop:hadoop:17772:0:99999:7:::" >> /etc/shadow
    [root@localhost ~]# id hadoop
    uid=600(hadoop) gid=5004(hadoop) groups=5004(hadoop)

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

    [root@localhost ~]# cp -r /etc/skel /home/hadoop && chown -R hadoop:hadoop -R /home/hadoop
    [root@localhost ~]# ls -ld /home/hadoop/
    drwxr-xr-x. 4 hadoop hadoop 4096 Sep  6 17:25 /home/hadoop/
    [root@localhost ~]# chmod 700 /home/hadoop/      
    [root@localhost ~]# ls -ld /home/hadoop/      
    drwx------. 4 hadoop hadoop 4096 Sep  6 17:25 /home/hadoop/

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

    [root@localhost ~]# chown -R hadoop:hadoop /home/hadoop/
    [root@localhost ~]# ls -la /home/hadoop/                
    total 28
    drwx------. 4 hadoop hadoop 4096 Sep  6 17:25 .
    drwxr-xr-x. 9 root   root   4096 Sep  6 17:25 ..
    -rwx------. 1 hadoop hadoop   18 Sep  6 17:25 .bash_logout
    -rwx------. 1 hadoop hadoop  176 Sep  6 17:25 .bash_profile
    -rwx------. 1 hadoop hadoop  124 Sep  6 17:25 .bashrc
    drwx------. 2 hadoop hadoop 4096 Sep  6 17:25 .gnome2
    drwx------. 4 hadoop hadoop 4096 Sep  6 17:25 .mozilla

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

    [root@localhost ~]# grep -i "^s" /proc/meminfo 
    SwapCached:            0 kB
    SwapTotal:       4095992 kB
    SwapFree:        4095992 kB
    Shmem:              3268 kB
    Slab:             111268 kB
    SReclaimable:      51960 kB
    SUnreclaim:        59308 kB
    [root@localhost ~]# grep -E "^(s|S)" /proc/meminfo 
    SwapCached:            0 kB
    SwapTotal:       4095992 kB
    SwapFree:        4095992 kB
    Shmem:              3268 kB
    Slab:             111248 kB
    SReclaimable:      51956 kB
    SUnreclaim:        59292 kB

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

    [root@localhost ~]# 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
    mike:x:500:500:mike_pang:/home/mike:/bin/bash
    tom:x:501:502::/home/tom:/bin/bash
    bhps:x:502:503:test:/home/bhps/:/bin/bash
    mysql:x:27:27:MySQL Server:/var/lib/mysql:/bin/bash
    jerry:x:503:504::/home/jerry:/bin/bash
    weblogic:x:504:505::/home/weblogic:/bin/bash
    gentoo:x:505:5001::/users/gentoo:/bin/bash
    hadoop:x:600:5004::/home/hadoop:/bin/bash

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

    [root@localhost ~]# grep "/bin/bash$" /etc/passwd  
    root:x:0:0:root:/root:/bin/bash
    mike:x:500:500:mike_pang:/home/mike:/bin/bash
    tom:x:501:502::/home/tom:/bin/bash
    bhps:x:502:503:test:/home/bhps/:/bin/bash
    mysql:x:27:27:MySQL Server:/var/lib/mysql:/bin/bash
    jerry:x:503:504::/home/jerry:/bin/bash
    weblogic:x:504:505::/home/weblogic:/bin/bash
    gentoo:x:505:5001::/users/gentoo:/bin/bash
    hadoop:x:600:5004::/home/hadoop:/bin/bash

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

    [root@localhost ~]# grep -E "\<[[:digit:]]{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
    dbus:x:81:81:System message bus:/:/sbin/nologin
    vcsa:x:69:69:virtual console memory owner:/dev:/sbin/nologin
    haldaemon:x:68:68:HAL daemon:/:/sbin/nologin
    saslauth:x:498:76:"Saslauthd user":/var/empty/saslauth:/sbin/nologin
    postfix:x:89:89::/var/spool/postfix:/sbin/nologin
    ntp:x:38:38::/etc/ntp:/sbin/nologin
    apache:x:48:48:Apache:/var/www:/sbin/nologin
    avahi:x:70:70:Avahi mDNS/DNS-SD Stack:/var/run/avahi-daemon:/sbin/nologin
    gdm:x:42:42::/var/lib/gdm:/sbin/nologin
    sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
    tcpdump:x:72:72::/:/sbin/nologin
    mysql:x:27:27:MySQL Server:/var/lib/mysql:/bin/bash

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

    [root@localhost ~]# grep -E "^[[:space:]]+" /boot/grub/grub.conf 
            root (hd0,0)
            kernel /vmlinuz-2.6.32-279.el6.x86_64 ro root=UUID=9fe4ae1b-2605-4ca5-9b8c-b557301a9fb8 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-279.el6.x86_64.img

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

    [root@localhost ~]# grep -E "^#[[:space:]]+[^[:space:]]+" /etc/rc.d/rc.sysinit 
    # /etc/rc.d/rc.sysinit - run once at boot time
    # Taken in part from Miquel van Smoorenburg's bcheckrc.
    # Check SELinux status
    # Print a text banner.
    # Only read this once.
    # Initialize hardware
    # Set default affinity
    # Load other user-defined modules
    # Load modules (for backward compatibility with VARs)
    # Configure kernel parameters
    # Set the hostname.
    # Sync waiting for storage.
    # Device mapper & related initialization
    # Start any MD RAID arrays that haven't been started yet
    # Remount the root filesystem read-write.
    # Clean up SELinux labels
    # If relabeling, relabel mount points.
    # Mount all other filesystems (except for NFS and /proc, which is already
    # mounted). Contrary to standard usage,
    # filesystems are NOT unmounted in single user mode.
    # The 'no' applies to all listed filesystem types. See mount(8).
    # Update quotas if necessary
    # Check to see if a full relabel is needed
    # Initialize pseudo-random number generator
    # Configure machine if necessary.
    # Clean out /.
    # Do we need (w|u)tmpx files? We don't set them up, but the sysadmin might...
    # Clean up /var.
    # Clean up utmp/wtmp
    # Clean up various /tmp bits
    # Make ICE directory
    # Start up swapping.
    # Set up binfmt_misc
    # Boot time profiles. Yes, this should be somewhere else.
    # Now that we have all of our basic modules loaded and the kernel going,
    # 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
    # Let rhgb know that we're leaving rc.sysinit

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

    [root@localhost ~]# netstat -tan |grep -E "LISTEN[[:space:]]+$"
    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      
    tcp        0      0 :::22                       :::*                        LISTEN      
    tcp        0      0 ::1:631                     :::*                        LISTEN      
    tcp        0      0 ::1:25                      :::*                        LISTEN 

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

    [root@localhost ~]# useradd bash -s /sbin/nologin && useradd testbash -s /sbin/nologin && useradd basher -s /sbin/nologin && useradd nologin -s /sbin/nologin
    [root@localhost ~]# tail -4 /etc/passwd
    bash:x:601:601::/home/bash:/sbin/nologin
    testbash:x:602:602::/home/testbash:/sbin/nologin
    basher:x:603:603::/home/basher:/sbin/nologin
    nologin:x:604:604::/home/nologin:/sbin/nologin
    [root@localhost ~]# grep "/sbin/nologin$" /etc/passwd|cut -d: -f1
    bin
    daemon
    adm
    lp
    mail
    uucp
    operator
    games
    gopher
    ftp
    nobody
    dbus
    usbmuxd
    avahi-autoipd
    vcsa
    rtkit
    abrt
    haldaemon
    saslauth
    postfix
    ntp
    apache
    avahi
    pulse
    gdm
    sshd
    tcpdump
    mariadb
    bash
    testbash
    basher
    nologin
    评论 1
    添加红包

    请填写红包祝福语或标题

    红包个数最小为10个

    红包金额最低5元

    当前余额3.43前往充值 >
    需支付:10.00
    成就一亿技术人!
    领取后你会自动成为博主和红包主的粉丝 规则
    hope_wisdom
    发出的红包
    实付
    使用余额支付
    点击重新获取
    扫码支付
    钱包余额 0

    抵扣说明:

    1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
    2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

    余额充值