The “#” in the following information indicates that the operation is performed as the root user

The article directories

  • I. Operation mode
  • Ii. User and User Group Management (emphasis)
    • 1. User management
      • ① Adding a User
      • ② Modifying a user
      • ③ Set a password
      • ④ Deleting a User
    • 2. User group management
      • ① Adding a user group
      • ② User group editing
      • ③ The user group is deleted
  • Three, network Settings
  • Proprietary services are services that do not require the user to install software independently, but can be used directly when the system is installed (built-in).

I. Operation mode

  • Run mode can also be called run level.
  • In Linux, there is a process init (initialize) whose id is 1.
  • View the process:# ps -ef|grep init

  • There is a configuration file for this process:inittab(System runlevel configuration file, location /etc/inittab)
  • Main contents of the document:

Based on the above description, you can see that there are seven runlevels/modes in Centos6.5

  • 0 – Indicates the shutdown level (do not set the default run level to this value)
  • 1 – Single user mode
  • 2 – Multi-user mode, without NFS (Network File Syetem)
  • 3 – Multi-user mode, full multi-user mode (no desktop, pure command line mode)
  • 4 — Patterns not in use (Reserved patterns)
  • 5 — X11, full graphical interface mode
  • 6 – Represents the restart level (do not set the default run level to this value)

Several commands related to this level:

  • # init 0Said power off
  • # init 3Indicates to switch to the mode without desktop
  • # init 5Switch to the graphical interface
  • # init 6Restart the computer

Note: The init directive requires super administrator privileges and cannot be executed by ordinary users.

These commands are actually calledinitThe process passes the number (runlevel) to the process, which reads the configuration file to perform the corresponding operation.

  • ① Switch to the pure command line mode (temporary switch, restart and resume)
# init 3
Copy the code

  • After the switchover, you need to enter the user name and password.*“Prompt input, as long as you confirm the input password is not wrong, press Enter.
  • ② Return to desktop mode
# init 5
Copy the code
  • ③ Set the mode to the command line mode permanently



    /etc/inittabIn the fileinitdefaultValue is set to3And restart the operating system.

Ii. User and User Group Management (emphasis)

  • Linux is a multi-user and multi-task operating system. Any user who wants to use system resources must apply for an account from the system administrator and use the account to access the system.
  • On the one hand, the user account can help the system administrator to track the users using the system and control their access to system resources. On the other hand, it can also help users organize files and provide security protection for users.
  • Each user account has a unique user name and its own password.
  • After the user enters the correct user name and password during login, the user can enter the system and its home directory.
  • In order to achieve the management of user accounts, the work to be completed mainly includes the following aspects:
  • Add, delete and modify user accounts and manage user passwords.
  • Manage user groups.

Note three files:

  • /etc/passwdStore key user information
  • /etc/groupStore key information about user groups
  • /etc/shadowStore user password information

1. User management

① Adding a User

  • Common syntax:# useradd option user name
  • Common options:

    -g: indicates the primary user group of the specified user. The value can be of the user groupidCan also be a group name

    -g: indicates the additional user group of the specified user. The value can be of the user groupidCan also be a group name

    – u:uid, the user’sid(User’s identifier),By default, they are allocated from 500 to 500uid, if you do not want to use the system allocation, you can use this option to customize [similar to Tencent QQ’s self-selected numbers]

    – c:commenT Add a comment
  • Example: Creating a userzhangsan, without any options

  • Verification is successful:

    A. validation/etc/passwdThe last line of thezhangsanThe information;

    B. Check whether there is a home directory (after the user is created in Centos, a home directory with the same name is generated);

Expansion: knowledgepasswdfile

  • User name: Password: User ID: User group ID: Note: Home directory: interpreter shell
  • User name: Create a user name that you need to enter during login.
  • Password: The password position is usually “X”, indicating the password placeholder.
  • User ID: the user’s identifier;
  • User group ID: indicates the ID of the primary group to which the user belongs.
  • Comment: explain what the user does;
  • Home directory: the default location after the user logs in to the system;
  • Interpreter shell: After the user enters the system, the interpreter will collect the user’s input instructions and pass them to the kernel for processing.

Note: When no options are added, useradd is followed by a series of actions

  • A. Create a home directory with the same name.
  • B. Create a user group with the same name.

  • Example: add option, create user lisi, add group 501 to lisi, add group 500 to LISi, select id 666.





  • Pay attention to: View the primary group of the userpasswdFiles can be viewed by viewing attached groupsgroupFile.

② Modifying a user

  • Common syntax:# usermod Option user name

    Usermod:user modify, user modification
  • Common options:

    -g: indicates the primary user group of the specified user. The value can be the ID or name of the user group

    -g: indicates the additional user group of the specified user. The value can be the ID or name of the user group

    – u:uid, the user’sid(User identifier), which is assigned from 500 to 500 by defaultuid, if you do not want to use the system allocation, you can use this option to customize [similar to Tencent QQ’s self-selected numbers]

    -l: Changes the user name

  • Example: Change the primary user group of Zhangsan to 500 and the additional user group to 501
# usermod -g 500 -G 501 zhangsan
Copy the code
  • Example: Change the name of a zhangsan user to wangerma
# usermod -l New username Old username # usermod -l wangerma zhangsanCopy the code

③ Set a password

  • Linux does not allow users to log in to the system without a password, so the previously created users are currently locked and require a password to log in to the computer.
  • Common syntax:# passwd Specifies the user name
  • Case: SetupwangermaUser password

  • When setting the password, there is no input prompt. Please enter the password and press Enter to ensure that the password entered twice is the same.
  • You can also use a weak password, but it is not recommended, otherwise you will see the following prompt:

  • After setting the passwordshadowIn the document: can be seenlisiThe user doesn’t have a password.

  • You can log in to an account after setting a user password, as required herewangerma

  • Switch user command:# su [username]Switch (user)
  • If the user name is not specified, the system switches torootThe user.

  • Note the following when switching users:

    From a.rootSwitching to a normal user does not require a password, but vice versarootPassword;

    B. After the user is switched, the working path remains unchanged.

    C. Common users cannot access itrootUser home directory, but vice versa;

④ Deleting a User

  • Common syntax:# userdel option user name
  • Userdel:user delete(User deletion)
  • Common options are as follows: -r: Deletes the user’s home directory at the same time.
  • Case: DeletewangermaThe user

  • Pay attention to: Already logged inwangermaWhen deleting a user, a message is displayed indicating deletion failure, but no user logs inlisiYou can delete it normally.
  • Solution: Blunt and simple,killAll processes of the user

  • Tip: all commands that operate with the user (exceptpasswd) onlyrootThe super administrator has permission to execute the command.

2. User group management

  • Each user has a user group. The system can manage all users in a user group in a centralized manner. For example, users in Linux belong to a user group with the same name. This user group is created at the same time when users are created.
  • User group management involves adding, deleting, and modifying user groups. The addition, deletion, and modification of groups are actually pairs/etc/groupUpdate files.



    File structure:

    User group name: Password: User group ID: indicates the user name in the group

    Password:XRepresents a placeholder. Although passwords can be set for user groups, most of the time no password is set.

    Intra-group user name: Indicates the user name of the additional group.

① Adding a user group

  • Common syntax:# groupAdd Option User group name
  • Common options:

    -g: similar to “in user Add”-u“,-gIndicates that you can set a user-defined user group ID. If you do not specify a user group ID, the value increases from 500 by default.
  • Case: UsegroupaddCommand to create a new user group namedAdministrators

② User group editing

  • Common syntax:# groupmod Option User group name
  • Common options are as follows: -g: similar to -u in user modification. -g indicates that you need to set a user-defined user group ID. -n: Similar to -l in user modification, you need to set a new user group name
  • Case: ModificationAdministratorsUser group, change the group ID from 502 to 520, change the group name toadmins

③ The user group is deleted

Common syntax:# groupdel Specifies the user group name

  • Pay attention to: If a group needs to be deleted but the group is the primary group of a user, it cannot be deleted. If you do need to delete users, remove all users from the group first.

Three, network Settings

  • First know the location of the nic configuration file:/etc/sysconfig/network-scripts

  • Name the configuration file of the nic in the directory:ifcfg– Nic name

  • ONBOOT: Indicates whether to start
  • BOOTPROTO: indicates the IP address assignment mode. DHCP indicates the dynamic host assignment protocol
  • HWADDR: Hardware address, MAC address

  • What do I do if I need to restart the NIC?
# service network restart
Copy the code

  • There may be no service command to quickly manipulate services in some branch versions, but there is a common directory:/etc/init.d

    This directory contains shortcuts to the right services.
  • The reboot command can also be used here:
# /etc/init.d/network restart
Copy the code

  • Extension 1: If you modify the configuration file of a NETWORK adapter but the directory level of the configuration file is very deep, you can create a shortcut (soft connection) in the shallow directory to facilitate future search
# ln -s Path to the original file shortcut pathCopy the code

  • throughls -lThe following effects can be listed:



    L in the file type position indicates that the file type is link, and -> indicates the original file path.
  • Extension 2: How do I restart a single NIC?

    Stopping a network adapter:# ifDown Indicates the name of the nic

    Enable a NETWORK adapter:# ifup Indicates the name of the nic
  • For example, to stop and start (restart) eth0, enter the value
# ifdown eth0
# ifup eth0
Copy the code
  • Tip: do not ban network cards at will in the actual work.