1, the Replication/etc/skel directory is/home/tuser1, requires/home/tuser1 and its internal files belong to the group and other users do not have any access rights.
[[email protected] ~]# cp -r /etc/skel/ / home/tuser1 #使用cp命令带-R option: recursively replicate directories and all internal content; [[email protected] ~]# ll /home/ | grep tuser1 #查看/ home/tuser1 Directory file Details drwxr-xr-x. 2 root root 4096 8 Month 23 22:06 tuser1[[email protected] ~]# chmod go= /home/tuser1 #修改文件属组 (g) and Other (o) permissions [[email protected] ~]# ll /home/ | grep tuser1 # View modified file permissions drwx------. 2 root root 4096 8 month 23 22:06 tuser1[[email protected] ~]#
2. Edit the/etc/group file and add the group Hadoop.
[[email protected] ~]# vim/etc/group #使用vim编辑器打开/etc/group File # Use the letter "G" to jump to the end of the file, press "O" below the current line to insert into the input mode. #编辑内容 "hadoop:x:2021:", press "ESC" to exit the input mode and enter edit mode. #键入 ":" Into the command line mode, enter "Wq" to save the exit. Or, type "ZZ" in edit mode to save the exit. [Email protected] ~]# Cat/etc/group | grep Hadoop #查看编辑结果hadoop: X:2021:[[email protected] ~]# #其中 "hadoop:x:2021:" One ":" As a delimiter, divided into four paragraphs, respectively, corresponding to the # Group name: Group Password: GID: The current group as an additional group User list (delimiter is comma)
3. Manually edit the/etc/passwd file to add a new line, adding user Hadoop, whose basic group ID is the Hadoop group ID number; its home directory is/home/hadoop.
#首先了解下/etc/passwd file content format [[email protected] ~]# cat/etc/passwd #查看/etc/passwd file contents root:x:0:0:root:/root:/bin/bash# This article To hold the user and its attribute information, using the ":" Delimiter, divided into 7 fields # format: name:password:uid:gid:gecos:directory:shell# (1) Name: username. # (2) Password: the password is represented by an X (encrypted, stored in the shadow file/etc/shadow), shadow file can only be read as root. # (3) uid:uid (user ID). # (4) Gid:gid group identification. # (5) GECOS: User information, usermod-c specified when modifying or creating a user. # (6) Directory: Home directory. # (7) Shell: Login using the shell. [[email protected] ~]# vim/etc/passwd #使用vim编辑器打开, #使用字母 "G" jump to the end of the file, press "O" below the current line to insert into the input mode. #编辑内容 "Hadoop:x:1001:2021::/home/hadoop:/bin/bash", Save exit
4. Copy the/etc/skel directory as/home/hadoop, which requires that the genus Group and other users of the Hadoop directory be modified without any access rights.
[[email protected] ~]# cp-r/etc/skel//home/hadoop #复制/etc/skel directory for/home/hadoop[[email protected] ~]# chmod-r go= /home/hadoop #修改hadoop目录的属组和其它用户没有任何访问权限. #修改目录权限命令chmod, the format is as follows #chmod [OPTION] ... Octal-mode file...# [option]:-r: Recursive Modify permissions #chmod [option] ... Mode[,mode] ... FILE ... #修改一类用户的所有权限: # mode:u=[,g=,o=] or go= or a= ("=" followed by permission type r,w,x) #修改一类用户某位或某些位权限 # mode:u+ U-Add or modify Permissions #chmod [OPTION]. . --reference=rfile file...# refer to rfile file for permission, change file to the same rfile;
5, modify the/home/hadoop directory and all the internal files of the owner of Hadoop, belong to Hadoop group.
[Email protected] ~]# chown-r hadoop:hadoop/home/hadoop #修改文件的属主: Chown#chown [OPTION] ... [OWNER] [: [GROUP]] file...# [OPTION]:-r: Recursive # Usage: (Note: ":" In the command is available.) replace;) # OWNER only modifies the master # Owner:group modified owner: Genus Group #: Group only modifies genus Group
6. Display the lines in the/proc/meminfo file beginning with uppercase or lowercase s, in two ways;
#方法一:[[email protected] ~]# grep -i ' ^s ' /proc/meminfo# method two:[[email protected] ~]# grep ^[ss] /proc/meminfo #使用命令grep #grep [OPTIONS] Pattern [file ...] # [options]: # --color=auto: match to the text shaded display;# -v: display lines that cannot be matched to the pattern; -i: ignore character capitalization; # -o: Displays only the matched string;# -q: silent mode and does not output any information;# -A #:after, show match to Line and after # line # -b #: before, Front # line # -c #:context, before and after each # line # &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;-E: Using Egrep; extending regular Expressions # pattern:# .: matches any single character;# []: matches any single character in the specified range # [^ ]: matches any single character outside the specified range # ': Single quote, strong reference # "": double quotes, weak reference # *: Matches the preceding character any number of times, including 0 times # .*: Any character of any length;# \?: matches the preceding character 0 or 1 times; the preceding is optional; # \+ : matches the preceding character at least 1 times; # \{m\}: Matches the preceding character m times;# \{m,n\}: Matches the preceding character at least m times, up to N times;#  Position anchor: # ^: Anchor at the beginning of the line; the leftmost;# for the pattern $: End of line anchoring; the rightmost;# for the pattern ^PATTERN$: for pattern matching whole line;# ^$: Empty Line;# ^[[:space:]]*$: Blank line # \< or \b: The first anchor of the word; for the left;# \> of the word pattern or \b: the ending anchor; for the right side of the word pattern; # \<pattern\ Match whole word;# regular special character set # [[:d igit:]] : Matching numbers [0-9]# [[:lower:]] : Matching lowercase letters [a-z]# &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;[[:UPPER:]]&NBSP;&NBSP: Match capital letters [A-Z]# [[:p unct:]] : Match Special characters # [[:space:]] : Match spaces # &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;[[:ALPHA:]]&NBSP;&NBSP;&NBSP: Matching Letters [a-zA-Z]# &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;[[:ALNUM:]]&NBSP;&NBSP: Match letters and numbers [0-9a-za-z]
7. Display the default shell of the/etc/passwd file as a non-/sbin/nologin user;
[Email protected] ~]# grep-v '/sbin/nologin$ '/etc/passwd
8. Display the user whose default shell is/bin/bash in/etc/passwd file;
[[email protected] ~]# grep '/bin/bash$ '/etc/passwd | Cut-d:-f1
9. Find out one or two digits in the/etc/passwd file;
[[email protected] ~]# grep ' \<[0-9]\{1,2\}\> '/etc/passwd
10. Display the line beginning with at least one blank character in/boot/grub/grub.conf;
[Email protected]lhost ~]# grep ' ^[[:space:]]\+ '/boot/grub/grub.conf
11, the display/etc/rc.d/rc.sysinit file with the beginning of #, followed by at least one white space character, and then have at least one non-whitespace character line;
[[email protected] ~]# grep ' ^[#[:space:]\+].*[^[:space:]\+]$ '/etc/rc.d/rc.sysinit
12, the Netstat-tan command execution results in the "LISTEN", followed by or with a blank character end of the line;
[Email protected] ~]# Netstat-tan | grep ' lished.*[:space:]*$ '
13, add user bash, Testbash, basher, Nologin (this one user's shell is/sbin/nologin), and then find the current system on its user name and the default shell of the same user information;
[Email protected] ~]# useradd bash && useradd testbash && useradd basher && useradd-s/sbin/nolo Gin Nologin [[email protected] ~]# grep "^\ ([[: alnum:]]\+\>\). *\1$"/etc/passwd or use [[email protected] ~]# egrep "^ ([[: alnum:]]+\>). *\1$ "/etc/passwd
This article from "blog" blog, declined reprint!
Megeedu Linux+python Advanced Operations 3 period four weeks