The third week of work -N42- open-minded

A display under / etc / directory, beginning with a non-alphabetic, a letter followed by a file of any length and any other characters or directory

  ls  /etc/[^[:alpha:]][[:alpha:]]*

Second, copy / etc / directory all names beginning with the p, ending in a non-digital files or directories to / tmp / mytest1 directory

  mkdir /tmp/mytest1

  cp -a /etc/p*[^[:digit:]] /tmp/mytest1

Third, the contents of / etc / issue file conversion to save a file after capital /etc/issue.out

  tr 'a-z' 'A-Z' < /etc/issue

[root@centos7 ~]# tr 'a-z' 'A-Z' < /etc/issue
\S
KERNEL \R ON AN \M

Fourth, the summary description please use the direction of the user and group management class command and complete the following exercises

1, user management

(1), useradd: user-created

  useradd [options] LOGIN

  Options:
    -u UID: UID specified, minimum and maximum UID defined in /etc/login.defs
    -o: with -u option not checked UID uniqueness
    -g GID: Basic specified user belongs to the group, can be group name, may also be the GID; if not specified, the user name of the same group name
    -c "COMMNET": the user's comment information
    -d HOME_DIR: specifies the user's home directory; initial content in the home directory / etc / skel / under
    -D: represents user to modify the default options; (modified is / etc / default / useradd in option), -D as the useradd, the SHELL the useradd -s -D, -D -b base_dir the useradd
    -s the SHELL : indicates that the user's default shell, list the shell is available in the / etc / shells
    -G GROUP1, GROUP2: additional specified group of users, can have multiple, separated by commas, the group must exist prior
    -N: do not create private group group shots, the shots using the group group users
    -r: Create system user, CentOS6: ID <500, CentOS7: ID <1000
    -m: creating home directory for users of the system
    -M: home directory is not created, a non-system user

(2), usermod: Modify User Properties

  usermod [options] LOGIN

  Options:
    -u UID: new UID
    -g GID: new main group
    -G GROUP1, GROUP2, ...: Additional new group, the original group will be additional coverage, if you keep the original, will have to use the -a option representing an additional
    -s SHELL: new default SHELL
    -c "the cOMMENT": the new annotation information
    -d hOME: home directory, the home directory of the original files are not moved to the new home directory, as you want to move, then use -m option
    -l login_name: new name
    -L: lock the user, increase the password field in / etc / shadow of!
    -U: unlock the user, the / etc / shadow password bar! Remove
    -e YYYY-MM-DD: Expiration date specified user account
    -f INACTIVE: (number of grace days after the password expires) deadline set inactive

(3), userdel: Delete User

  userdel [options] LOGIN

  Options:
    -r: delete the user's home directory

(4), id: ID view user-related information

  id [options]... [user]

  Options:
    -u: display UID
    -g: show GID
    -G: displays the ID of the user belongs to the group
    -n: display name, need to use with ugG

(5), su: switch user

  su UserName: nonlogin type switch that does not read the target user's profile, does not change the current working directory

  su - UserName: Log type switch, reads the target user's profile, switch to the home directory, complete switch

(6), passwd: modify the specified user's password

  passwd [options] UserName

  Options:
    -d: delete the specified user password
    -l: Lock the specified user
    -u: To unlock a specific user
    -e: force users to change password at next logon (the password expiration)
    -f: force operation
    -n mindays: specifying a minimum lifetime
    - x maxdays: the maximum period of use
    -w warndays: how many days in advance to start warning
    -i inactive-days: inactive period
    --stdin: from standard input to receive the user's password, such as echo "pASSWORD" | passwd --stdin USERNAME

(7), chage: change the user password attribute

  chage [options] LOGIN

  Options:
    -m: Modify the minimum password lifetime
    -M: Change Password maximum period of use
    -d LAST_DAY: last modification time to modify user password
    -I INACTIVE: modify the user inactivity period
    -E EXPIRE_DATE: modify the user's password expiration date
    -W WARN_DAYS: change password days warning
    -l password policy display
  example:
    the first log chage -d 0 tom forced password reset
    -m 0 -M 42 is -I. 7 -W 14 Tom the chage
    the chage -E 2016-09- 10 tom

2, group management command

(1), groupadd: Create a group

  groupadd [options] group

  Options:
    -g GID: specify the GID
    -r: Create a system group
    -n: Group renamed

(2), groupmod: Modify Attribute Group

  groupmod [options] group

  Options:
    -g GID: new GID
    -n group_name: Group renamed

(3), groupdel: Delete group

  groupdel GROUP

(4), gpasswd: change the group password

  gpasswd [option] GROUP

  Options:
    -a user: add user to a specific group
    -d user: remove users from the specified user group
    -A user1, user2, ...: to set a list of users have administrative rights group

(5), newgrp: temporary main switch group

  If the user does not belong to this group, you need to set a password

Exercise:

(1), create groups distro, its GID of 2019;

  groupadd -g 2019 distro

[root@centos7 ~]# groupadd -g 2019 distro
[root@centos7 ~]# tail -n 1 /etc/group
distro:x:2019:

(2) creating a user Mandriva, its ID number is 1005; substantially Distro group;

  useradd -u 1005 -g distro mandriva

[root@centos7 ~]# useradd -u 1005 -g distro mandriva
[root@centos7 ~]# id mandriva
uid=1005(mandriva) gid=2019(distro) groups=2019(distro)

(3) create a user mageia, its ID number is 1100, the home directory is / home / linux;

  useradd -u 1100 -d /home/linux mageia

[root @ centos7 ~] # useradd -u 1100 -d / of home / linux mageia 
[root @ centos7 ~] # id mageia 
uid = 1100 (mageia) gid = 1100 (mageia) Groups = 1100 (mageia) 
[root @ centos7 ~ ] # -II -d / of home / linux / 
drwx ------ 3 mageia mageia 78 Nov 11  18 : 49 / of home / linux /

(4), to add the user mageia password, the password is mageedu, and user passwords expire after 7 days;

  echo "mageedu" | passwd --stdin mageia

  passwd -x 7 mageia

[root@centos7 ~]# echo "mageedu" | passwd --stdin mageia
Changing password for user mageia.
passwd: all authentication tokens updated successfully.
[root@centos7 ~]# passwd -x 7 mageia 
Adjusting aging data for user mageia.
passwd: Success
[root@centos7 ~]# chage -l mageia 
Last password change                    : Nov 11, 2019
Password expires                    : Nov 18, 2019
Password inactive                    : never
Account expires                        : never
Minimum number of days between password change        : 0
Maximum number of days between password change        : 7
Number of days of warning before password expires    : 7

(5), delete mandriva, but keep the other directories;

  userdel mandriva

[root@centos7 ~]# userdel mandriva 
[root@centos7 ~]# ll -d /home/mandriva/ 
drwx------ 3 1005 distro 78 Nov 11 18:48 /home/mandriva/

(6), to create a user Slackware, its ID number is 2002, the basic group Distro, additional sets of peguin;

  groupadd peguin

  useradd -u 2002 -g distro -G peguin slackware

[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), to modify the default shell for user slackware / bin / tcsh;

  usermod -s /bin/tcsh

[root@centos7 ~]# tail -n 1 /etc/passwd
slackware:x:2002:2019::/home/slackware:/bin/bash
[root@centos7 ~]# usermod -s /bin/tcsh slackware
[root@centos7 ~]# tail -n 1 /etc/passwd
slackware:x:2002:2019::/home/slackware:/bin/tcsh

(8), to add additional user slackware Admins group;

  groupadd admins

  usermod -a -G admins slackware

[root @ centos7 ~ ] # groupadd Admins 
[root @ centos7 ~] # # the usermod -a -G Admins Slackware and use -G - A option indicates that additional 
[root @ centos7 ~] # the above mentioned id Slackware 
uid = 2002 (Slackware) gid = 2019 (Distro) Groups = 2019 (Distro), 2020 (peguin), 2021 (Admins) 
[the root centos7 @ ~] # the usermod - Ga Slackware # Admins such wording not 
the usermod: Group ' A ' does exist not 
[the root @ centos7 ~] # the usermod -G - A Slackware # Admins such wording nor 
the usermod: Group '-a' does not exist
[root@centos7 ~]# gpasswd -d slackware admins    #从组中删除用户 
Removing user slackware from group admins
[root@centos7 ~]# id slackware
uid=2002(slackware) gid=2019(distro) groups=2019(distro),2020(peguin)
[root@centos7 ~]# usermod  -G admins -a slackware  #此种写法可以
[root@centos7 ~]# id slackware
uid=2002(slackware) gid=2019(distro) groups=2019(distro),2020(peguin),2021(admins)

Guess you like

Origin www.cnblogs.com/hovin/p/11836871.html