Linux user management

  

First, add user terminal command to add user 1.useradd stu //add new user stu according to the default parameters

2.useradd -d /tmp/yc -s /bin/ksh -p ycpass stu01//Add new user stu01 Specify stu01 home directory location user login shell and password

3.useradd -n stu02 //Create user stu02 Do not create corresponding group stu02

4. Useradd -DGROUP=100 HOME=/home INACTIVE=-1 EXPIRE=SHELL=/bin/bashSKEL=/etc/skelCREATE_MAIL_SPOOL=yes//Display system default parameter options content

5.adduser command in RedHat The adduser command is a symbolic link to the useradd command. The two are actually the same command [root@localhost rc0.d]# cd /usr/sbin[root@localhost sbin]# ls -l adduserlrwxrwxrwx 1 root root 7 05-03 19:34 adduser -> useradd

Modify file add user [root@localhost sbin]#cat /etc/passwdroot:x:0:0:root:/root:/bin/bash//username : Password: User ID: Group ID: User full name: User working directory: User login shell

Second, set user password [root@localhost ~]#passwd stu01 //Set stu01 user port Application examples: 1. User stu01 forgot login password, request administrator help method 1: [root@localhost ~]#passwd -d stu01[root@localhost ~]#su stu01Change password by this user Method 2: [root@localhost ~]#vi /etc/passwd find the record line of the user in the passwd file, delete the "X" flag of the password field and save the execution [root@localhost ~]#su stu01

2.stu02 Because the business travel request administrator locks the account [root@localhost ~]#passwd -l stu02[root@localhost ~]#exitusers return after the business trip and the administrator unlocks [root@localhost ~]#passwd -u stu02

Third, add users in batches Method 1: Use the newusers command to add users in batches 1. Edit a passwd file with the same format, including all the text files that need to be created, named newuser.txt. As follows: [root@localhost ~]# vi newuser.txt st01:st0101:601:601::/home/st01:/bin/bashst02:st0102:602:602::/home/st02:/bin/bashst03:st0103 :603:603::/home/st03:/bin/bashst04:st0104:604:604::/home/st04:/bin/bashst05:st0105:605:605::/home/st05:/bin/bashst06: St0106:606:606::/home/st06:/bin/bashst07:st0107:607:607::/home/st07:/bin/bashst08:st0108:608:608::/home/st08:/bin/bash

2. Execute the command to add the user [root@localhost ~]# newusers newuser.txt

Method 2: Add a user using a shell script

Four, modify the password in batches The chpasswd command adds users in batches. 1. Edit a text file. It contains all the user names and new passwords to be modified. The user name and the new password are one-to-one. Name the file chpass.txt to save [root@localhost ~]# Vi chpass.txt stu01:abcdstu02:abcdstu03:abcdstu04:abcdstu05:abcdstu06:abcdstu07:abcdstu08:abcd2. Finally execute the command [root@localhost ~]# chpasswd<chpass.txt

5. Delete user 1. Terminal Command delete [root@localhost ~]#userdel -r stu01//delete stu01 user -r parameter delete stu01 user home directory

2. Modify file deletion First, delete the corresponding line of the user in /etc/passwd and /etc/shadow files, and force recursively with rm -rf Delete the user's work face and all the home directories and files in the directory. Finally, delete the line corresponding to the user group in the /etc/group file.

VI. Modify the user attribute 1. Modify the user attribute by the terminal command. The terminal command is usermod. The usage of this command is similar to the useradd command. Application example: [root@localhost ~]#usermod -L stu01//invalidizes the stu01 user password

2. Modify the passwd file First, modify /The domain corresponding to this user attribute in etc/passwd and /etc/shadow files. Second, use the mv command to rename the user's working directory. Finally, modify the line corresponding to the user group in the /etc/group file.

Copyright © Windows knowledge All Rights Reserved