Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of user Management and grep regular expression in linux system

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces the linux system user management and grep regular expression example analysis, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.

User Management and grep regular expression in linux system

1. Copy / etc/skel directory to / home/tuser1, which requires that the affiliated groups and other users of / home/tuser1 and its internal files do not have any access rights.

[root@suywien ~] # cp-rpv / etc/skel/ / home/tuser1/'/etc/skel/'->'/ home/tuser1/''/etc/skel/.mozilla'->'/ home/tuser1/.mozilla''/etc/skel/.mozilla/extensions'->'/ home/tuser1/.mozilla/extensions''/etc/skel/.mozilla/plugins'->'/ home/tuser1/.mozilla/plugins''/etc/skel/.bash_logout' ->'/ home/tuser1/.bash_logout''/etc/skel/.bash_profile'->'/ home/tuser1/.bash_profile''/etc/skel/.bashrc'->'/ home/tuser1/.bashrc' [root@suywien ~] # useradd tuser-d / home/tuser1/useradd: warning: the home directory already exists.Not copying any file from skel directory into it. [root@suywien ~] # chmod-R go-rwx / home/tuser1/ [root@suywien ~] # ll-d / home/tuser1/drwx- 3 root root 74 Feb 12 03:04 / home/tuser1/

2. Edit the / etc/group file and add the group hadoop.

[root@suywien ~] # vim / etc/group [root@suywien ~] # tail-1 / etc/grouphadoop:x:1029

3. Manually edit the / etc/passwd file to add a new line and add the user hadoop. Its basic group ID is the id number of the hadoop group; its home directory is / home/hadoop.

[root@suywien ~] # vim / etc/passwd [root@suywien ~] # tail-1 / etc/passwdhadoop:x:1029:1029::/home/hodoop/:/bin/bash

4. Copy / etc/skel directory to / home/hadoop, which requires that the subordinate groups and other users who modify the hadoop directory do not have any access rights.

[root@suywien ~] # cp-fpv / etc/skel/ / home/hadoopcp: omitting directory'/ etc/skel/' [root@suywien ~] # cp-fpvR / etc/skel/ / home/hadoop'/etc/skel/'->'/ home/hadoop''/etc/skel/.mozilla'->'/ home/hadoop/.mozilla''/etc/skel/.mozilla/extensions'->'/ home/hadoop/.mozilla/extensions''/etc/skel/.mozilla / plugins'->'/ home/hadoop/.mozilla/plugins''/etc/skel/.bash_logout'->'/ home/hadoop/.bash_logout''/etc/skel/.bash_profile'->'/ home/hadoop/.bash_profile''/etc/skel/.bashrc'->'/ home/hadoop/.bashrc' [root@suywien ~] # chmod go-rwx / home/hadoop/ [root@suywien ~] # ls-ld / home/hadoop/drwx -3 root root 74 Feb 12 03:04 / home/hadoop/

5. Modify the / home/hadoop directory and all its internal files. The owner is hadoop, and the group is hadoop.

[root@suywien] # chown-R hadoop:hadoop / home/hadoop/ [root@suywien] # ll-al / home/hadoop/total 16drwx3 hadoop hadoop 74 Feb 12 03:04. Drwxr-xr-x. 10 root root 4096 Mar 25 10:14.-rw-r--r-- 1 hadoop hadoop 18 Nov 20 2015. Bash _ logout-rw-r--r-- 1 hadoop hadoop 193 Nov 20 2015. Bash _ profile-rw-r--r-- 1 hadoop hadoop 231 Nov 20 2015. Bashrcdrwxr-xr-x 4 hadoop hadoop 37 Feb 12 03:03 .Mozilla

6. Display lines in the / proc/meminfo file that begin with uppercase or lowercase S; in two ways

[root@suywien ~] # grep ^ [Stemags] / proc/meminfo SwapCached: 0 kB SwapTotal: 2097148 kB SwapFree: 2097148 kB Shmem: 9100 kB Slab: 89476 kB SReclaimable: 53176 kB SUnreclaim: 36300 kB [root@suywien ~] # grep-I "^ s" / proc/meminfo SwapCached: 0 kB SwapTotal: 2097148 kB SwapFree: 2097148 kB Shmem: 9100 kB

7. Show users whose default shell is not / sbin/nologin in the / etc/passwd file

[root@suywien ~] # grep\ / sbin\ / nologin$ / etc/passwdbin: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/nologinmail:x:8:12:mail:/var/spool/mail:/sbin/nologin.

8. Display the user whose default shell is / bin/bash in the / etc/passwd file

[root@suywien ~] # grep\ / bin\ / bash / etc/passwdroot:x:0:0:root:/root:/bin/bashroo:x:1000:1000:root:/home/roo:/bin/bashgentoo:x:4001:4001::/home/gentoo:/bin/bashmageia:x:1100:1100::/home/linux:/bin/bashtuser:x:4003:4003::/home/tuser1/:/bin/bashhadoop:x:1029:1029::/home/hodoop/:/bin/bash

9. Find one or two digits in the / etc/passwd file

[root@suywien ~] # grep "\" / etc/passwdmail: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/nologin.

10. Display lines in / boot/grub/grub.conf that begin with at least one white space character

[root@suywien ~] # grep "^ [[: space:]]\ +" / boot/grub2/grub.cfg load_env set default= "${next_entry}" set next_entry= save_env next_entry set boot_once=true.

11. Display a line in the / etc/rc.d/rc.sysinit file that begins with #, followed by at least one white space character, followed by at least one non-white space character

[root@suywien ~] # grep "^ # [[: space:]]\ + [^ [: space:]]\ +" / etc/rc.d/rc.local # THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES# It is highly advisable to create own systemd services or udev rules# to run scripts during boot instead of using this file.# In contrast to previous versions due to parallel execution during boot# this script will NOT be run after all other services.# Please note that you must run 'chmod + x / etc/rc.d/rc.local' to ensure# that this script will be executed during boot.

12. Type the line after 'LISTEN', or ending with a white space character in the execution result of the netstat-tan command

[root@suywien ~] # netstat-tan | grep "LISTEN [[: space:]] * $" tcp 0 0 192.168.122.1 LISTEN 53 0.0.0.0 * LISTEN tcp 00 0.0.0.0 22 0.0.0.0 * LISTEN tcp 0 0127.0.0.1 tan 631 0.0.0.0 * LISTEN tcp 0 0127.0.0.0.1 25 0.0.0.0 LISTEN tcp6 0 0: 22: * LISTEN tcp6 0 0:: 1 LISTEN tcp6 0 0:: 1:25: * LISTEN

13. Add users bash, testbash, basher, nologin (the shell of this user is / sbin/nologin), and then find out the information of the user whose user name is the same as the default shell on the current system.

[root@suywien ~] # useradd bash [root@suywien ~] # useradd basher [root@suywien ~] # useradd-s / sbin/nologin nologin [root@suywien ~] # grep-E "^ ([^:] +\ >). *\ 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:4004:4004:: / home/bash:/bin/bashnologin:x:4006:4006::/home/nologin:/sbin/nologin Thank you for reading this article carefully I hope the article "user Management of linux system and sample Analysis of grep regular expressions" shared by the editor will be helpful to you. At the same time, I hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report