Add, delete, modify, and delete users in linux

Source: Internet
Author: User
Tags addgroup

Add, delete, modify, and delete users in linux

Http://blog.csdn.net/pipisorry/article/details/39533627

1. Create a user:

1. Run the useradd command.

Useradd
Function Description: create a user account.
Syntax: useradd [-mMnr] [-c <remarks>] [-d <logon directory>] [-e <validity period>] [-f <buffer days>] [-g <group>] [-G <group>] [-s] [-u] [User Account] Or useradd-D [-B] [-e <validity period>] [- f <buffer days>] [-g <group>] [-G <group>] [-s]
Note: useradd can be used to create a user account. After the account is created, use passwd to set the password of the account, and use userdel to delete the account. The account created using the useradd command is actually saved in the/etc/passwd text file.
Parameters:
-C <remarks> Add remarks. The remarks are saved in the remarks field of passwd.
-D <logon directory> specifies the start directory for user login.
-D. Change the default value.
-E <validity period> specifies the validity period of the account.
-F <buffer days> specifies the number of days after the password expires.
-G <group> specifies the group to which the user belongs.
-G <group> specifies the additional group to which the user belongs.
-M automatically creates the user's logon directory.
-M: do not automatically create a user's logon directory.
-N cancel creating a group named by the user name.
-R: Create a system account.
-S specifies the shell used after the user logs on.
-U indicates the user ID.

Example: useradd dapi -- create user dapi
Useradd-e 12/30/2014 pipi2 -- create pipi2 and specify expiration period

The user's default UID is increased from 1000 to backward order, and less than 1000 is reserved as the system account. You can specify UID,

Example: useradd-u 1600 pipi3

When creating a user, you must specify a user group for the new user. If you do not specify the workgroup to which the user belongs, a workgroup with the same name as the user name is automatically generated.

Specify the Contact Group pipi when creating a user's dapi, for example, useradd-g pipi dapi.

2. Use the passwd command to set a password for the new user.
Example: passwd dapi
Note: users who do not have a password cannot use it.

3. Run The usermod command to modify the user account.

Usermod
Function Description: modify a user account.
Syntax: usermod [-LU] [-c <remarks>] [-d <logon directory>] [-e <validity period>] [-f <buffer days>] [-g <group>] [-G <group>] [-l <Account Name>] [-s] [-u] [User Account]
Note: usermod can be used to modify user account settings.
Parameters:
-C <remarks> modify the remarks of the user account.
-D logon directory> modify the directory when a user logs in.
-E <validity period> modifies the validity period of an account.
-F <buffer days> change the number of days after the password expires to close the account.
-G <group>: Modify the group to which the user belongs.
-G <group> modify the additional group to which the user belongs.
-L <Account Name> modify the user account name.
-L lock the user password to make it invalid.
-S: Modify the shell used after user login.
-U: Modify the user ID.
-U unlocks the password.
-------------------------------------------------------

For example, change user1's logon name to u1,
Usermod-l u1 user1
For example, change the user's dapi to the pipi group,
Usermod-g pipi dapi
For example, change the user1 directory to/users/us1.
Usermod-d/users/us1 user1

4. Run The userdel command to delete a user account.

Userdel
Function Description: delete a user account.
Syntax: userdel [-r] [User Account]
Note: userdel can delete user accounts and related files. If no parameter is added, only the user account is deleted, and related files are not deleted.
Parameters:
-F Delete the user's logon directory and all files in the directory.
----------------------------------------------------------

Example: delete user user2
Userdel user2
For example, delete user3 and its working directory.
Userdel-r user3

5. View user information
Id command -- view the UID and GID of a user

Example: id user4
Finger command-you can view the user's home directory, startup shell, user name, address, phone number, and other information
Example: finger user4

2. User Group:

6. Run groupadd to create a user group.
Groupadd-g 888 users
Create a group of users whose GID is 888

7. Command gpasswd to add users to the group
Only the root and Group administrators can change the group members:
For example, add user1 to the users group.
Gpasswd-a user1 users
For example, withdraw user1 from the users group.
Gpasswd-d user1 users

8. Run groupmod to modify the group.
Groupmod-n user users modify group name user to users

The/etc/group file contains all groups.
All usernames in the/etc/shadow and/etc/passwd Systems
Method for modifying the group to which the current user belongs
Usermod or you can directly modify the/etc/paaawd file.

9. Delete groupdel
Groupdel users

Test instance:

Like windows, ubuntu can be used to create or delete new users at will. In windows, it is relatively simple. In ubuntu, commands are required, but the operations are not very complicated.

Create a new ubuntu user?

First open the terminal and enter: # sudo adduser ddpp

The system may prompt the following information:

Adding User "username "...

Adding new group "username" (1001 )...

Adding new user "username" (1001) to group "username "...

Create the home directory "/home/username "...

Copying the file from "/etc, skel...

Enter a new UNIX Password: (Note that you do not enter the password of your current user, but enter the password you want to create a new user)

Re-enter the new UNIX Password: (try again)

Passwd: the password is successfully updated.

Changing the user information for username
Enter the new value, or press ENTER for the default
Full Name []: ddpp (enter the Name of the new user)
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Is this information correct? [Y/n] y

# Passwd dapi Note: users without a password cannot use it.

Enter a new UNIX Password: (Note that you do not enter the password of your current user, but enter the password you want to create a new user)

Re-enter the new UNIX Password: (try again)

Passwd: the password is successfully updated.

In this step, the new user has been added successfully. Now we can use ls/home to check it. If username ddpp is displayed, it indicates that the user has been created successfully.

Delete ubuntu users?

Ubuntu deletes users in the same terminal. Note that,If the user to be deleted is logged on, it cannot be deleted.The message "userdel: user XXX is currently logged in" must be logged out and switched to another user before deletion. For example, I just created a new user named ddpp. For example, I have logged on to the desktop with the user ddpp. If I want to delete the user named ddpp, it cannot be deleted. The correct method is to log out of ddpp, log on to the desktop with root, and then delete ddpp.

Run the sudo userdel username command to delete the ubuntu user. After the user is deleted successfully, no prompt is displayed.

PS: (Other commands)

Userconf

Function Description: sets a program for a user account.
Syntax: userconf [-- addgroup <group>] [-- adduser <user ID> <group> <User Name>] [-- delgroup <group>] [-- deluser <user ID>] [-- help]
Note: userconf is actually a symbolic connection to linuxconf and provides graphical interface operations for administrators to establish and manage various accounts. If no parameters are added, the graphic interface is displayed.
Parameters:
-- Addgroup <group> adds a group.
-- Adduser <user ID> <group> <User Name> adds a user account.
-- Delgroup <group> deletes a group.
-- Deluser <user ID> deletes a user account.
-- Help: displays help.
------------------------------------------------------

Whois

Function Description: search for and display user information.
Method: whois [Account name]
Note: The whois command will search for and display the user information of the specified account, because it is found in the WHOIS database of Network Solutions, so the account name must be registered above for retrieval, the name is case-insensitive.
---------------------------------------------------------
Whoami

Function Description: The user name is displayed first.
Syntax: whoami [-- help] [-- version]
Note: The user name is displayed. This command is equivalent to executing the "id-un" command.
Parameters:
-- Help Online help.
-- Version: displays the version information.
---------------------------------------------------

Who

Function Description: displays the user information currently logged on to the system.
Syntax: who [-Himqsw] [-- help] [-- version] [am I] [record files]
Note: If you execute this command, you will find that there are users logging on to the system. The terminals used to log on to the account will be listed when you execute the who command separately, the logon time and where to log in or which X monitor is being used.
Parameters:
-H or -- heading displays the title information columns of each column.
-I or-u or -- idle indicates the idle time. If the user performs any action within the previous minute, it indicates ". ", if the user has not performed any action for more than 24 hours, the" old "string is displayed.
-M this parameter has the same effect as the specified "am I" string.
-Q or -- count only displays the name and total number of accounts logged on to the system.
-S this parameter will be ignored and will not be processed. It is only responsible for solving compatibility issues with other versions of the who command.
-W or-T or -- mesg or -- message or -- writable displays the user information status bar.
-- Help Online help.
-- Version: displays the version information.

----------------------------------------------------
W

Function Description: displays the user information currently logged on to the system.
Syntax: w [-fhlsuV] [user name]
Note: If you execute this command, you can find out who are currently logged on to the system and the programs they are executing. Run w
The command displays all users. You can also specify a user name to display only information about a user.
Parameters:
-F. enable or disable the function to show where the user logs on to the system.
-H: The title information column of each column is not displayed.
-L use the detailed format list, which is the default value.
-S uses a concise format list, which does not display the User Logon Time, CPU time consumed by terminal jobs and programs.
-U ignores the name of the execution program and the CPU time consumed by the program.
-V displays the version information.
-----------------------------------------------------

Finger

The finger command is used to query user information. It usually displays the user name, main directory, stagnation time, Logon Time, logon shell, and other information of a user in the system. To query user information on a remote machine, you need to connect the user name to "@ host name" in the format of [user name @ host name]. However, the network host to be queried must run the finger daemon.

The common format of this command is:
Finger [Option] [user] [user @ host]
The meanings of the options in the command are as follows:
-S displays the user's registration name, actual name, terminal name, write status, stagnation time, Logon Time, and other information.
-L in addition to the information displayed with the-s option, it also displays information such as the user's home directory, logon shell, email status, and under the user's home directory. plan ,. project and. the content of the forward file.
-P is the same as the-l option except that the. plan and. project files are not displayed.
[Example] Run the finger command on the local machine.
$ Finger xxq
Login: xxq Name:
Directory:/home/xxq Shell:/bin/bash
Last login Thu Jan 1 21:43 (CST) on tty1
No mail.
No Plan.
$ Finger
Login Name Tty Idle Login Time Office Phone
Root * 1 28 Nov 25
......
----------------------------------------------------------------

Vlock(Virtual console lock)
Function Description: Lock a virtual terminal.
Syntax: vlock [-achv]
Note: Executing The vlock command can lock the virtual terminal to prevent other users from using it.
Parameters:
-A or -- all locks a terminal-phase job. If you use this parameter on a full-screen terminal, the keyboard is used.
The function of switching the terminal is disabled.
-C or -- current locks the current terminal-phase job, which is the default value.
-H or -- help Online help.
-V or -- version displays version information.
--------------------------------------------------------

From: http://blog.csdn.net/pipisorry/article/details/39533627

Ref: how to view users and user groups in linux

Http://blog.csdn.net/sin90lzc/article/details/7525670

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.