Linux User and account management, linux User Account
Linux is a multi-user multi-task time-sharing system. any user who wants to use system resources must first apply for an account from the system administrator, then enter the identity of this account to enter the system. On the one hand, the user's account can help the system administrator to track the users who use 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 account and password. After a user enters the correct account and password during logon, you can access the system and your home directory.
User Account Management
Add, delete, and modify user accounts
User Password Management
User Group Management
The management of user accounts mainly involves adding, modifying, and deleting user accounts. Adding a user account is to create a new account in the system, then allocate user numbers, user groups, home directories, logon shells, and other resources to the new account. The newly added account is locked and cannot be used to manage system users to add new user accounts.
Useradd option Username
Option
-C comment specifies an annotation description. -D directory specifies the user's main directory. If this directory does not exist, you can use the-m option to create a main directory. -G User Group specifies the user group to which the user belongs. -G user group, which specifies the additional group to which the user belongs. The-s Shell file specifies the user's logon Shell. -U user number specifies the user number of a user. If the-o option is available at the same time, the user ID of another user can be used again.
Delete account
Userdel option Username
The common option is-r, which is used to delete the user's home directory together.
Userdel-r user name
Modify account
Usermod option Username
The options are the same as those of useradd.
User Password Management
An important part of user management is the management of user passwords. The User Account has no password when it was created, but is locked by the system and cannot be used. You must specify a password for it to use, even if it is null.
Passwd option User Name
Option
-L the password is disabled. -U password unlock. -D indicates that the account has no password. -F forces the user to change the password upon next login.
System User Group Management each user has a user group. The system can centrally manage all users of a user. Different Linux systems have different user groups.
Add a new user group using the groupadd command
Groupadd option User Group
Option
-G GID specifies the group ID (GID) of the new user group ). -O is generally used together with the-g option, indicating that the GID of the new user group can be the same as the GID of the existing user group in the system.
Delete existing user groups
Groupdel User Group
Use the groupmod command to modify the attributes of a user group.
Groupmod option User Group
Option
-G GID: specify a new group ID for the user group. -O and-g options are used at the same time. The new GID of a user group can be the same as the GID of an existing user group in the system. -N new user group: Change the user group name to a new name.
If a user group belongs to multiple user groups at the same time, you can switch between user groups to have permissions for other user groups.
System files related to the user account in the newgrp user group/etc/passwd
The most important file involved in user management
User name: Password: User ID: Group ID: annotation Description: main directory: logon Shell
/Etc/shadow
The record corresponds to one-to-one in passwd, which is generated by the pwconv command based on the data in/etc/passwd.
Login Name: encrypted password: last modification time: minimum interval: maximum interval: warning time: inactive time: expiration time: Flag
/Etc/group
All user group information is stored in the/etc/group file.
When a user is a member of multiple groups at the same time, the main group to which the user belongs is recorded in the/etc/passwd file, that is, the default group to which the user belongs during logon, other groups are called additional groups.
Group Name: Password: Group ID: Add users to the group list to edit text User Files in batches-each column is written in passwd format, note that the user name, UID, and home directory of each user cannot be the same. Leave blank in the password column or enter the x number.
user001::600:100:user:/home/user001:/bin/bashuser002::601:100:user:/home/user002:/bin/bash
Run the command/usr/sbin/newusers as root to import data newusers <user.txt
Run/usr/sbin/pwunconv
Decode the shadow password generated by/etc/shadow, write it back to/etc/passwd, and delete the shadow password column of/etc/shadow, this is to facilitate the next step in password conversion, that is, to cancel the shadow passwd function first.
Edit the password reference document passwd.txt for each user
User001: Password user002: Password
Create a user password. shpasswd writes the password encoded by the/usr/bin/passwd command to the/etc/passwd password column.
chpasswd < passwd.txt
After confirming that the password is encoded and written to the/etc/passwd password column
Run/usr/sbin/pwconv to encode the password as shadow password and write the result to/etc/shadow.
pwconv
Linux disk management is directly related to the performance of the entire system
Commonly used Linux disk management Commands include df (list the total disk usage of the file system), du (check disk space usage), and fdisk (for disk partitioning)
Df
Df [-ahikHTm] [directory or file name]
Options and Parameters
-A: List all file systems, including system-specific/proc and other file systems;-k: displays each file system with KBytes capacity;-m: display file systems with the capacity of MBytes;-h: Display by yourself in easy-to-read formats such as GBytes, MBytes, and KBytes;-H: replace the carry mode of M = 1000 K with M = 1024 K;-T: displays the file system type, together with the filesystem name of the partition (for example, ext3);-I: the hard disk capacity is not used, but the inode quantity is used for display.
Du
Du [-ahskm] file or directory name
-A: lists all the files and directory capacities, because only the files under the directory are counted by default. -H: displayed in G/M format, which is easy to read.-s: only lists the total amount, rather than the occupied capacity of each directory.-S: excluding the total number of subdirectories, it is slightly different from-s. -K: displays the capacity in KBytes;-m: displays the capacity in MBytes;
Fdisk
Fdisk is a Linux operating tool for disk partition tables.
Fdisk [-l] device name
-L: Output all the partition content of the device connected to the backend. If there is only fdisk-l, the system will list the partitions of the devices that can be searched in the system.
Disk formatting
Mkfs [-t File System Format] Device File Name
-T: It can be connected to the file system format, such as ext3, ext2, and vfat. (It takes effect only when supported by the system)
Disk Inspection
Fsck [-t file system] [-ACay] device name
Used to check and maintain inconsistent file systems
-T: specifies the type of the file system. If a definition is already defined in/etc/fstab or the kernel itself supports it, this parameter-s is not required: run the fsck command one by one in sequence to check-A: checks all the partitions listed in/etc/fstab-C: displays the complete check progress-d: print the debug result-p of e2fsck: When both-A conditions are met, multiple fsck checks are executed together.-R: When both-A conditions are met, omitted/not checked-V: Detailed display mode-a: If the check is incorrect, it will be automatically repaired-r: if the check is incorrect, the user will answer whether to fix-y: the option specifies that yes is automatically entered for each file to be detected. If you are not sure about which files are abnormal, run # fsck-y to check and fix all files.
Attaching and deleting Disks
Disk mounting syntax
Mount [-t file system] [-o additional options] [-n] device name mount point
Disk detachment command syntax
Umount [-fn] device file or mount point
-F: Force disallow! It can be detached without upgrading/etc/mtab.
All Linux systems in Linux vi/vim have built-in vi text editors. Other text editors may not exist, but most of them use the vim Editor-vim has the ability to edit programs, it can actively identify the correctness of the syntax with the color of the font to facilitate programming.
Vim
Vim is a text editor developed by vi. It provides rich programming functions such as code supplement, compilation, and incorrect redirection. It is widely used by programmers, vi is an old-fashioned word processor, but its functions are quite complete, but there are still some improvements. vim is a good tool for program developers.
Vi and vim usage
Command mode |
Input mode |
Bottom line command mode |
1. I switch to the input mode 2. x Delete the character of the current cursor 3. Switch to the bottom line command mode and enter the command in the bottom line. |
1. In input mode, you can use the following buttons: 2. input characters-character buttons or use with shift (uppercase) 3. line feed -- Enter 4. delete a character before the cursor-Backspace 5. delete a character after the cursor -- del 6. move the cursor in the text-direction keys 7. move the cursor to the beginning or END of the line -- HOME/END 8. Page Up/Down 9. Switch the cursor to the input/replacement mode, and the cursor will become a vertical line/underline 10. Exit the command mode and switch to the command mode. |
In command mode, press: to display the bottom line command mode (the Esc key can exit the bottom line command mode at any time). The basic commands include: 1. q exit the program 2. Save the file |
Working Mode of the text editor
Commands for various scenarios in the text editor
In Linux, yumyum (Yellow dog Updater, Modified) is the Shell front-end Software Package Manager. Based on RPM package management, It can automatically download and install RPM packages from a specified server and automatically process dependencies, install all dependent software packages at a time, without tedious download and installation.
Yum provides commands for searching, installing, and deleting one or more software packages. The commands are concise and easy to remember.
Yum syntax
Yum [options] [command] [package]
Options: Optional. options include-h (help),-y (Select yes when prompted during installation), and-q (the installation process is not displayed)
Command: operation to be performed
Package: Operation object
Yum command
1. List all the software that can be updated the command: yum check-update2. Update all software commands: yum update3. install only the specified software command: yum install
4. update only the specified software command: yum update
5. Run the command yum list6. to delete software package: yum remove
7. search for the software package command: yum search
8. clear cache command: yum clean packages: Clear packages in the cache directory yum clean headers: Clear headersyum clean oldheaders in the cache directory old headersyum clean in the cache directory, yum clean all (= yum clean packages; yum clean oldheaders): clears the packages and old headers in the cache directory.
Domestic yum Source
Netease (163) yum source is one of the best yum sources in China. It can improve the speed of software package installation and update, and avoid the identification of some common software versions.