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

The method of using regular expressions for user Management in centos7

2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

1. Display / etc directory, starting with a non-letter, followed by a letter and other files or directories of any length and any character

[root@centos7 etc] # touch _ di234

[root@centos7 etc] # ls / etc/ | grep ^ [^ a-zA-Z] [a-zA-Z]. *

1sdf23

_ di234

[root@centos7 etc] #

2. Copy all files or directories that begin with p and end with non-numbers under the / etc directory to the / tmp/mytest1 directory.

[root@centos7 ~] # ls / etc/ | grep ^ p.* [^ 0-9] $

Pam.d

Passwd

Passwd-

Pbm2ppa.conf

Pinforc

Pki

Plymouth

Pm

Pnm2ppa.conf

3. Convert the contents of the / etc/issue file to uppercase and save to the / tmp/issue.out file

[root@centos7 ~] # cat / etc/issue | tr'amurz 'Amurz' > / tmp/mytest1

[root@centos7 ~] # cat / tmp/mytest1

\ s

KERNEL\ R ON AN\ M

[root@centos7 ~] #

4. Summarize and describe how to use user and group management commands and complete the following exercises:

(1) create a group distro with a GID of 2019

[root@centos7 ~] # groupadd-g 2019 distro

[root@centos7 ~] # cat / etc/group | grep distro

Distro:x:2019:

[root@centos7 ~] #

(2) create user mandriva, whose ID number is 1005; the basic group is distro

[root@centos7] # useradd-u 1005-g distro mandriva

[root@centos7 ~] # id mandriva

Uid=1005 (mandriva) gid=2019 (distro) groups=2019 (distro)

[root@centos7 ~] #

(3) create user mageia, whose ID number is 1100 and home directory is / homenux

[root@centos7] # useradd-u 1100-d / homenux mageia

[root@centos7 ~] # id mageia

Uid=1100 (mageia) gid=1100 (mageia) groups=1100 (mageia)

[root@centos7 ~] #

(4) add a password to the user mageia, the password is mageedu, and set the user password to expire after 7 days.

[root@centos7 ~] # echo mageedu | passwd-x 7-- stdin mageia

[root@centos7 ~] # cat / etc/shadow | grep mageia

Mageia:!!:18320:0:7:7:::

(5) delete mandriva, but keep its home directory

[root@centos7 ~] # userdel mandriva

[root@centos7] # ls-d / home/mandriva/

/ home/mandriva/

[root@centos7 ~] #

(6) create user slackware, whose ID number is 2002, basic group is distro, and additional group peguin

[root@centos7 ~] # groupadd peguin

[root@centos7] # useradd-u 2002-g distro-G peguin slackware

[root@centos7 ~] # id slackware

Uid=2002 (slackware) gid=2019 (distro) groups=2019 (distro), 2020 (peguin)

(7) modify the default shell of slackware to / bin/tcsh

[root@centos7] # usermod-s / bin/tcsh slackware

[root@centos7 ~] # grep slackware / etc/passwd

Slackware:x:2002:2019::/home/slackware:/bin/tcsh

[root@centos7 ~] #

(8) add additional group admins for user slackware

[root@centos7 ~] # groupadd admins

[root@centos7 ~] # usermod-G admins slackware

[root@centos7 ~] # id slackware

Uid=2002 (slackware) gid=2019 (distro) groups=2019 (distro), 2021 (admins)

[root@centos7 ~] #

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

Servers

Wechat

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

12
Report