Linux - Basic command usage

Linux -- basic command usage (Part 2)

1, linux user

1. What are users

Users are used to run some processes and own some files or directories.
In Linux, users are divided into three categories: root user , system users, ordinary users.
The user is uniquely identified by UID, and the root user UID is 0. The system user UID range is 1-999. The ordinary user UID starts from 1000 and accumulates successively by default.

What are system users?
Generally, the running processes belong to the system kernel processes, so the users running these processes are system users, and usually do not go to the system foreground, that is, the command interpreter shell Go inside and log in.

2. User related commands

useradd command ——To create a user, you usually need to set a password after creating the user

[root@localhost ~]# useradd wzg
[root@localhost ~]# passwd wzg

usermod command -- modify user attributes

-g -> Assign primary groups to users
-G -> Assign subordinate groups to users
-c -> Add a comment field for the user
-u -> Specify a for the user UID
-L -> Lock the user so that the user password is unavailable, such as continuously entering the wrong password
-U -> Unlock the user and make the user password available again

userdel command - delete user

userdel  user name -> The host directory is reserved without complete deletion
userdel  -r  user name  ->  Completely delete, and the host directory is deleted

Attached:
sudo command - > with root Run the command as (root user is a user with full privileges of the system. If you want to perform tasks such as installing or deleting software and managing system files, you must upgrade your privileges to root user)

id command - > view the information of the currently logged in user, or view the basic information of other users.

PS - Au - > view all processes running under the current terminal and display the associated users.

LS - L - > View user ownership of a file or directory. Or view the access rights of three types of users to a file

[root@localhost /]# ls -l
total 28
lrwxrwxrwx.   1 root root    7 Sep 21 12:53 bin -> usr/bin
dr-xr-xr-x.   3 root root 4096 Sep 21 12:58 boot
drwxr-xr-x.  20 root root 3260 Nov 16 19:51 dev
drwxr-xr-x. 141 root root 8192 Nov 16 19:53 etc
drwxr-xr-x.   6 root root   62 Oct 31 11:09 home
...

1st place in the first column:

  • L - > link represents: linked file
  • D - > directory represents: folder
  • Horizontal bar - Represents: ordinary document

The last 9 bits of the first column: (r readable, w writable, x executable)

  • The first group represents the access rights of the user to the file
  • The second group represents the access rights of the group to the file
  • The third group represents the access rights of other users to files (users other than their own users and groups)

The third column root represents that the user to which the file belongs is root

The fourth column root represents that the group to which the file belongs is the root group

3. Local user information

route: /etc/passwd

Format - > User Name: Password: UID: GID: Comments: Host Directory: Command environment

  • Password: save in shadow file with X instead
  • GID: after creating a new user, the system defaults to a group with the same name
  • Note: can be blank
  • Host Directory: / root or / home/dir
  • Command environment: / bin/bash or / sbin/nologin

/Bin / bash - > unlock the account, and the user can log in to the system using the shell
/SBIN / nologin - > lock the account. The user cannot log in to the system, but can run a program. If a user belongs to an insecure user, the user can be set as nologin

# practice
# Create a user named luna. There is no shell to log in to in the system
[root@localhost ~]# useradd luna
[root@localhost ~]# passwd luna
[root@localhost ~]# vim /etc/passwd
 find luna User, put/bin/bash Replace with:/sbin/nologin

4. User password information

/Etc / shadow - > store the password of the local user

Format - > User Name: Password: last password change date: minimum password usage period: maximum password usage period: password expiration warning period: available time after password Expiration: password expiration date: leave blank field

  • Password: * - > means there is no password and it is empty,! - > Represents that the user is disabled
  • Minimum service life of password: 0 - > indicates unlimited use
chage -User name command - set account expiration time
	-d  ->  Set the time for the last modification of the user's password from January 1, 1970
	-E  ->  Set account expiration date
	-I   ->  Set the time when the account can continue to log in to the system after expiration
	-m ->  Set the minimum number of days that the account can change the password
	-M ->  Set the maximum number of days before the account must change the password
	-W ->  Set the number of days of warning that the password is about to expire

2, Linux group

1. What is a group

Concept of main group:
When the system creates a user, it will assign a group to the user separately.
The fourth field GID definition in the / etc/passwd file.

  • Features: by default, the group name has the same name as the user name, and GID and UID have the same number. There is only one member in the group
  • Features: each user has only one main group, which is a 1:1 quantitative relationship.

Concept of subordinate group (additional group):
If a user is artificially added to an additional group and obtains the permissions of this group, this group is called a subordinate group or an additional group, which is a non primary group.
The last field definition in the / etc/group file.

  • Features: each user can have multiple subordinate groups, which is a 1: n quantitative relationship.
  • Features: conversely, a group can have multiple user members, that is, it can be a subordinate group of multiple users.

2. Group related commands

groupadd command -- create a group

-g  ->  Assign a new group GID

groupmod command -- modify an existing group - modify

-g  ->  Specify a new GID(Main group)
-G  ->  Specify additional groups
-n  ->  Specify a new groupname

groupdel command -- delete a group (you cannot delete a primary group belonging to another user)

# practice
# Create a group named groupone
# Create a user named harry, set the user ID to 2021, which belongs to the staff group, and this group is the additional group of the user
[root@localhost ~]# groupadd groupone
[root@localhost ~]# useradd -u 2021 -G groupone harry

3. Local group information

/Etc / group - > store local group information

Format - > group name: group password: GID: subordinate group user

  • Group password: replace with X, and the password is stored in / etc/gshadow file
  • Subordinate group users: that is, which users belong to this group

3, Linux package manager

1. What are rpm packages and yum sources

Red hat has two package managers, rpm and yum.

1. What is an rpm package?
The rpm package is similar to the exe file in Windows, but in Linux, a software usually needs to be installed by multiple RPMs, and there is an installation sequence between rpm packages, which is called dependency.

2. What is yum source?
Automatically analyze the dependency relationship between rpm packages, and realize the batch installation of installation packages. In Linux, to use yum, you need to configure a Yum source in advance to solve the dependency between rpm packages.

2. How to configure a local yum source:

To use the yum package manager, we first need a Yum warehouse, that is, a Yum source, which needs to be configured by ourselves.
The yum repository can use either a local repository (file) or a remote linked repository (http or ftp).

Specific operation steps:

(1) First, connect the system image file to the optical drive of the virtual machine in VMware;

(2) Mount the image in the optical drive:

[root@localhost ~]# mount /dev/cdrom /media

(3) Modify the yum source configuration file local repo (note that the file suffix is. repo, and the file name can be customized):

[root@localhost ~]# vim /etc/yum.repos.d/local.repo
	[rhel]
	name=rhel
	baseurl=file:///media
	enabled=1	#Means to open this yum warehouse, and 0 means to close this warehouse
	gpgcheck=0	#It means to verify the integrity (Security) of the warehouse software package. 0 means not to verify

(4) Empty yum source cache information:

[root@localhost ~]# yum clean all

(5) Retrieve current yum source information:

[root@localhost ~]# yum repolist

3. Package manager commands

rpm command usage:

-i  ->  install  ->  Install a package   dependencies (Dependent package)
-e  ->  erase  ->  Uninstall (delete) a package
-v  ->  Displays details throughout the installation process
-h  ->  with#The number shows the installation progress
-q  ->  query  ->  query
-f  ->  filename  ->  file name
-l  ->  list  ->  List documents

Common usage:

[root@localhost ~]# rpm -ivh yum-utils-1.1.31-40.el7.noarch.rpm	#Install a software package and display the detailed installation process to#The number shows the installation progress
[root@localhost ~]# rpm –qf /etc/chrony.conf	#Query which package a file (chrony.conf) is installed by
[root@localhost ~]# rpm -aq httpd	#Query the rpm package used by the corresponding service
[root@localhost ~]# rpm -ql httpd	#Query all files involved in the corresponding service, including data files and configuration files

yum command usage:

[root@localhost ~]# yum clean all	#Empty yum cache
[root@localhost ~]# yum repolist	#View the list of all yum sources in this operating system
[root@localhost ~]# yum list	        #Displays installed and available packages
[root@localhost ~]# yum provides + route	#Query the rpm package installed by a file
[root@localhost ~]# yum -y install + Software name	#Install a software
[root@localhost ~]# yum -y remove + Software name	#Uninstall a software
[root@localhost ~]# yum -y update + Software name	#Update a software
[root@localhost ~]# yum info	#Provides details related to the software package, including the disk space required for installation
[root@localhost ~]# yum history	#Query yum software management records
[root@localhost ~]# yum -y upgrade	#Upgrade system kernel

4, Network configuration and management of Linux

1. Network basic command

1. ifconfig command < = > IP addr show command - view the configuration information of all local network cards
Where, ens32: represents the local Ethernet network card, lo: represents the local loopback network card, and virbr0: represents the virtual network card

2. ping command -- test network connectivity (use ctrl+c to end the test)

3. ip route command - view local routes

4. tracepath command -- view the router address through which the target ip address passes

5. netstat command -- View network connection status
Netstat - pant - > View tcp protocol network port connection status with PID process information

6. ss command -- get system sockets statistics
SS - LT - > similar to the netstat -pant function, it can also be used to view the network connection status

2. Edit network profile

[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE=Ethernet	#The network card type is Ethernet
BOOTPROTO=none	#There are three ways to obtain ip addresses: dhcp obtains ip dynamically, none or static manually sets the fixed ip address
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens32				#Network card connection name
UUID=2c22b930-96b9-4ef4-abfb-ff9fbc85ff23	#System device ID number of the network card
DEVICE=ens32			#Device name
ONBOOT=yes				#Whether to start automatically
IPADDR=192.168.100.20	#IPv4 address
PREFIX=24				#Subnet mask, equivalent to NETMASK=255.255.255.0
GATEWAY=192.168.100.1	#gateway
DNS1=192.168.100.254	#DNS address. A network card can bind multiple DNS addresses
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes

3. Configure with the nmcli command

# View all network card connection information
[root@localhost ~]# nmcli connection show

# Delete the existing network card connection name ens32
[root@localhost ~]# nmcli connection delete ens32

# Add a new network card connection eth0 to the network card ens32 and set it to Ethernet type and startup
[root@localhost ~]# nmcli connection add con-name eth0 ifname ens32 type ethernet autoconnect yes

# Modify the network card connection eth0 as follows: manually add IPv4 address, IP address: 192.168.100.20/24, gateway address: 192.168.100.2, and the corresponding dns server address is 119.29.29.29
[root@localhost ~]# nmcli connection modify eth0 ipv4.method man ipv4.addresses 192.168.100.20/24 ipv4.gateway 192.168.100.2 ipv4.dns 119.29.29.29
		
# Open network card connection eth0
[root@localhost ~]# nmcli connection up eth0

#If the network card cannot be connected, you can close the connection first and then turn it on
[root@localhost ~]#nmcli connection down eth0

# Reload all network card connection configurations
[root@localhost ~]# nmcli connection reload

# Because the network card configuration has been modified, you need to restart the network service of the system
[root@localhost ~]# systemctl restart network

# Check whether the network is configured properly
[root@localhost ~]# ifconfig

# Or check whether the configuration file is correct
[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0

# Test whether the newly configured local network can be ping ed
[root@localhost ~]# ping 192.168.100.20

Keywords: Linux Operation & Maintenance server

Added by _spaz on Wed, 05 Jan 2022 20:36:17 +0200