System version:
[[email protected] ~]# cat /etc/redhat-release CentOS release 6.7 (Final)[root[email protected] ~]# uname -r2.6.32-573.el6.x86_64
[[email protected] ~]# cat /etc/redhat-release CentOS Linux release 7.1.1503 (Core) [[email protected] ~]# uname -r3.10.0-229.el7.x86_64
1. Copy the/etc/skel directory as/home/tuser1, requiring/home/tuser1 and its internal files to have no access to the group and other users
[[email protected] ~]# cp -rv /etc/skel/ /home/tuser1#注意:事先无需创建/home/tuser1目录,否则这条命令会变成复制/etc/skel目录到/home/tuser1目录下`/etc/skel/‘ -> `/home/tuser1‘`/etc/skel/.bash_logout‘ -> `/home/tuser1/.bash_logout‘`/etc/skel/.bashrc‘ -> `/home/tuser1/.bashrc‘`/etc/skel/.bash_profile‘ -> `/home/tuser1/.bash_profile‘[[email protected] ~]# chmod -R go-rwx /home/tuser1[[email protected] ~]# ll -a /home/tuser1/total 20drwx------. 2 root root 4096 Jul 3 17:03 .drwxr-xr-x. 3 root root 4096 Jul 3 17:03 ..-rw-------. 1 root root 18 Jul 3 17:03 .bash_logout-rw-------. 1 root root 176 Jul 3 17:03 .bash_profile-rw-------. 1 root root 124 Jul 3 17:03 .bashrc
2. Edit the/etc/group file, add the group Hadoop
[[email protected] ~]# grep ‘777‘ /etc/group#这里没有grep到任何内容,表示“777”这个组ID没有被占用;#注意:在centos6中系统组ID的范围是1-499,登录组是500-60000[[email protected] ~]# echo ‘hadoop:x:777:‘ >> /etc/group[[email protected] ~]# tail -1 /etc/grouphadoop:x:777:
3. Manually edit the/etc/passwd file to add a new line of user Hadoop, whose base group ID is the Hadoop group ID number; its home directory is/home/hadoop
[[email protected] ~]# grep ‘777‘ /etc/passwd#首先还是要确认“777”这个UID有没有被占用,没有grep到,表示没有被占用;#在centos6中,登录用户的UID范围和登录组GID范围一样是500-60000[[email protected] ~]# echo ‘hadoop:x:777:777::/home/hadoop:/bin/bash‘ >> /etc/passwd[[email protected] ~]# tail -2 /etc/passwdfedora:x:500:500::/home/fedora:/bin/bashhadoop:x:777:777::/home/hadoop:/bin/bash
4. Copy the/etc/skel directory as/home/hadoop, requiring that the genera and other users of the Hadoop directory be modified without any access rights
[[email protected] ~]# cp -rv /etc/skel/ /home/hadoop`/etc/skel/‘ -> `/home/hadoop‘`/etc/skel/.bash_profile‘ -> `/home/hadoop/.bash_profile‘`/etc/skel/.bash_logout‘ -> `/home/hadoop/.bash_logout‘`/etc/skel/.bashrc‘ -> `/home/hadoop/.bashrc‘[[email protected] ~]# chmod go= /home/hadoop/[[email protected] ~]# ll -d /home/hadoop/drwx------. 2 root root 4096 Jul 4 13:55 /home/hadoop/
5. Change the owner of the/home/hadoop directory and all its internal files to Hadoop, a group of Hadoop
[[email protected] ~]# chown -R hadoop:hadoop /home/hadoop/[[email protected] ~]# ll -a /home/hadoop/total 20drwx------. 2 hadoop hadoop 4096 Jul 4 13:55 .drwxr-xr-x. 6 root root 4096 Jul 4 13:55 ..-rw-r--r--. 1 hadoop hadoop 18 Jul 4 13:55 .bash_logout-rw-r--r--. 1 hadoop hadoop 176 Jul 4 13:55 .bash_profile-rw-r--r--. 1 hadoop hadoop 124 Jul 4 13:55 .bashrc
6. Displays lines in the/proc/meminfo file that begin with uppercase or lowercase s;
[[email protected] ~]# grep -i "^s" /proc/meminfo SwapCached: 0 kBSwapTotal: 2031612 kBSwapFree: 2031612 kBShmem: 188 kBSlab: 69812 kBSReclaimable: 10648 kBSUnreclaim: 59164 kB或 [[email protected] ~]# grep "^[Ss]" /proc/meminfo或 [[email protected] ~]# grep "^\(S\|s\)" /proc/meminfo或 [[email protected] ~]# grep -E "^(S|s)" /proc/meminfo
7. Display the user whose default shell is non-/sbin/nologin in the/etc/passwd file
[[email protected] ~]# grep -v "/sbin/nologin" /etc/passwd | cut -d: -f1rootsyncshutdownhaltcentosfedoraarchlinuxhadoop
8. Display the user whose default shell is/bin/bash in the/etc/passwd file
[[email protected] ~]# grep "/bin/bash" /etc/passwd | cut -d: -f1rootcentosfedoraarchlinuxhadoop
9. Find one or two digits in the/etc/passwd file
[[email protected] ~]# grep "\<[0-9]\{1,2\}\>" /etc/passwdroot:x:0:0:root:/root:/bin/bashbin:x:1:1:bin:/bin:/sbin/nologindaemon:x:2:2:daemon:/sbin:/sbin/nologinadm:x:3:4:adm:/var/adm:/sbin/nologinlp:x:4:7:lp:/var/spool/lpd:/sbin/nologinsync:x:5:0:sync:/sbin:/bin/syncshutdown:x:6:0:shutdown:/sbin:/sbin/shutdownhalt:x:7:0:halt:/sbin:/sbin/haltmail:x:8:12:mail:/var/spool/mail:/sbin/nologinoperator:x:11:0:operator:/root:/sbin/nologingames:x:12:100:games:/usr/games:/sbin/nologinftp:x:14:50:FTP User:/var/ftp:/sbin/nologinnobody:x:99:99:Nobody:/:/sbin/nologindbus:x:81:81:System message bus:/:/sbin/nologintss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologinpostfix:x:89:89::/var/spool/postfix:/sbin/nologinsshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin或 grep "\<[0-9][0-9]\?\>" /etc/passwd
10. Display lines that begin with at least one whitespace character in/boot/grub/grub.conf
[[email protected] ~]# grep "^[[:space:]]\+" /boot/grub/grub.conf root (hd0,0) kernel /vmlinuz-2.6.32-573.el6.x86_64 ro root=/dev/mapper/VolGroup-lv_root rd_NO_LUKS LANG=en_US.UTF-8 rd_NO_MD rd_LVM_LV=VolGroup/lv_swapSYSFONT=latarcyrheb-sun16 crashkernel=auto rd_LVM_LV=VolGroup/lv_root KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet
11. Displays lines with # Beginning with #, followed by at least one white space character, and then at least one non-whitespace character in the/etc/rc.d/rc.sysinit file
[[email protected] ~]# grep "^#[[: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)....
Netstat-tan command execution results with ' LISTEN ', followed by a line ending with a white space character
[[email protected] ~]# 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 :::22 :::* LISTEN tcp 0 0 ::1:25 :::* LISTEN
13. User bash, Testbash, basher, Nologin (this one user's shell is/sbin/nologin), and then find out the current system on the user name and the default shell of the same user information
[[email protected] ~]# grep "^\([^:]\+\>\).*\1$" /etc/passwdsync:x:5:0:sync:/sbin:/bin/syncshutdown:x:6:0:shutdown:/sbin:/sbin/shutdownhalt:x:7:0:halt:/sbin:/sbin/haltbash:x:778:778::/home/bash:/bin/bashnologin:x:781:781::/home/nologin:/sbin/nologin
Linux Basics Exercises (II.)