Linux basics: Basic Environment and system management, linux System Management
I. Linux User and permission management
-User management
-Linux user configuration file:/etc/passwd
Root: x: 0: 0: root:/bin/bash
User name: Password: User id: Group id: User Group: Home Directory: shell
-Add users: only root users can manage all users
-"Useradd: Used to add users. The user ID starts from 500 by default.
Useradd username
Useradd erongda01 erongda01: x: 500: 500:/home/erongda01:/bin/bash
Create a user at the same time: create a user's home directory in/home
-Set Password
Passwd erongda01
-Delete a user
Userdel erongda02: by default, only users are deleted, and home directories are not deleted.
Userdel-r erongda01: Delete the home directory while deleting the user
-Switch users
Su: used to switch users
Format: su-username
-"User group: group
-Configuration file:/etc/group
-Create a group
Groupadd groupname
-Delete a group
Groupdel groupname
-"Permission management: Linux has strict permission management
-Rw-r --. 1 root 1658 Mar 13 passwd
Type + number of permission links user group size last access date file name
-> Rw-r --
1st bits: file type
-: File
D: Directory
B: Block devices
C: character file
L: Link
-"2, 3, 4: indicates the permission of the file owner
-"5, 6, and 7: indicates the permissions of users in the same group.
-, 10 digits: Permission of others
User Type: owner u same group user g others o Owner
Permission type: Read r write w execute (x)
-Change permissions:
-Character change permission
Chmod o + x testfile.txt
Chmod o-r testfile.txt
Chmod a + r testfile.txt
-"Digital permission change"
Rwx => 421 => 7 => 111
Chmod 755 testfile.txt
Rwxr-xr-x
7 5
-Change the owner or group of the file
Chown username: groupname file_path
Chown rdedu: rdedu testfile.txt
Chown rdedu: testfile.txt
Chown-R rdedu: rdedu file_path: modify all files in the directory
-Change the group to which the file belongs
Chgrp rdedu testfile.txt
2. Common tool commands
-"Mongodo: used to configure normal users to execute advanced permission commands
-"Mongodo: in essence, the configuration file is modified:/etc/sudoers
Root ALL = (ALL) ALL
What is the logon address of the user name? What is the command executed by the user?
Rdedu ALL = (root)/sbin/service iptables status
-Execution method: Add sudo to the front of the command.
Sudo service iptables status
-Configuration
Rdedu ALL = (ALL) NOPASSWD: ALL
-Common symbolic commands
-".: Indicates the current directory
Cp/root/install. log ./
-"...: Indicates the directory at the upper level
-"|: Pipeline operator, usually used with the grep command to transmit command execution results
Grep: used for text filtering
Cat/etc/passwd | grep 'root'
->: Rewrite Overwrite
Standard Input: stdin
Standard output: stdout
Echo "hello"> testOut.txt
->: Redirect append
Echo "hadoop"> testOut.txt
-"~ : Represents the Home Directory
-&: Indicates that the program runs in the background.
-"\: Line Break, indicating that the command has not ended
-Text Editor vi/vim
-Used to edit or create text
-Three modes:
Command mode: Run quick commands
-"G: Jump to the last line
-"Gg: Jump to the first line
-"Yy: copy the current cursor row
-P: Paste
-U: undo the previous operation.
-"Dd": Cut the current row.
10dd
-"I: insert in the current row
-"O: insert data in the next row of the current row
-"O: insert the last row of the current row
Insert mode
-Exit insert mode: ESC
Shift +:
Last line mode:
Set nu: Add row number
/String: Search for strings
1, $ s/nologin/88888/g
1: starting from the first line
$: Last line
S: Indicates replacement.
G: If a row appears multiple times, replace all
Exit: q
Force Exit: q!
Save and exit: wq, x
-Man: The HELP command used to view the document or command user manual.
-"Man ls
-"Find: Search for files
Format: find path condition [name, size, owner, type]
Find/etc-name init *
Find/etc-name init
-Size: search by size
Find/etc-size + 10000
Size: block (default B), character (c), k, M, G
-Scope and conditions:
+: Greater
-: Less
-Logical connection
-A: and coordinate condition
-O: or condition
Find/etc-size + 10000-a-size-100000
-Type: file type
F: File
D: Directory
-User
-Group
-"Du": Count the folder size.
-A: Count all files in the subfolders.
-S: only the file directory size is displayed.
-H: user-friendly display, add your own unit
-Wc: Word statistics
Wc file
3 4 20 testOut.txt
Number of lines, number of words, and number of characters
-L: line
-W: word
-C: char
Iii. disk management in Linux
-Fdisk: used to manage all hard disk devices in Linux
-"Create a primary partition:
-Fdisk management sdb
Fdisk/dev/sdb
Extended partition (create logical partition) + primary partition <= 4
1 + 2
-Format
Mkfs. ext4/dev/sdb1
-Temporary mounting
Mount/dev/sdb1/partition/primary
-Permanent mounting
Vim/etc/fstab
/Dev/sdb1/partition/primary ext4 defaults 0 0
-Create a logical partition:
-Create an extended partition
-Create logical partitions
-Restart
-Format logical shard
-Mount
Iv. System Management
-Network:
Ifconfig: Used to view and configure network information
Route-n: route
-"Service Management
-"Service: used to manage the startup, shutdown, viewing status, and restart of a service
Service iptables status/stop/start/restart
/Etc/init. d/iptables
-"Chkconfig: Set the startup
Chkconfig iptables -- list: view the startup status
Chkconfig iptables off: Disable startup
Chkconfig iptables on: Enable startup
-"Port
Netstat-atunlp
A: All
T: tcp protocol
U: udp protocol
P: Display pid
L: listen, listener
-Process management commands
Top: Resource Manager related to windows
Free: view memory information,
Ps: process
Ps-ef
Jps: java process
Kill: kill, used to close the process
Kill-9 1
-Disable selinux
Vim/etc/selinux/config
SELINUX = disabled