Add/delete users and user groups in Linux (adding CVS users in Linux is actually adding Linux users .)

Source: Internet
Author: User
Tags ftp access
Source: http://www.cnblogs.com/xd502djj/archive/2011/11/23/2260094.html

This article summarizes some common commands and parameters used to add or delete users and user groups in Linux.
1. User Creation:
Adduser sunxuezhi // create a sunxuezhi user
Passwd sunxuezhi // set the sunxuezhi user and change the password

2. Create a working group
Groupadd test // create a test workgroup

3. Create a user and add a Working Group
Useradd-g test phpq // create a phpq user and add it to the test workgroup

Note: shell used by-G's group-D home directory-S

 

Others:

View the user group:

After logging on with the current user, run the groups command.

 

Preparations:

To add a CVS user in Linux, because CVS is on Linux,

Adding a CVS user is equivalent to adding a liunx user.

(Proposal: it is best to divide users into one group when adding users .)

 

4. Add a working group for existing users
Usermod-G groupname Username

Or: gpasswd-a user group

5. temporarily close: Add * before the second field (password) of the user's row in the/etc/shadow file. To restore the user, remove.

You can also use the following command to disable the user account:
Passwd Peter-l

Release again:
Passwd Peter-u

6. Permanently delete user accounts
Userdel Peter

Groupdel Peter

Usermod-G Peter (Force delete all files and subdirectories in the user's home directory and Home Directory)

7. delete a user from the group
Edit/etc/group, locate the group1 line, and delete
Or use the command
Gpasswd-d a group

8. Display User Information
Id user
CAT/etc/passwd

For more information about users and user groups, see
Linux users and user groups
This document describes the concepts of user and group management in Linux, and lists commands related to user and group; it also provides explanations on single-user multi-task and multi-user multi-task.

This article from PhP news original link: http://www.phpq.net/linux/linux-add-delete-user-group.html

Linux User and user group management overview

Understand the concept of single-user multitasking and multi-user multitasking in Linux;

Linux is a multi-user, multi-task operating system; we should understand the concept of single-user multi-task and multi-user multi-task;


1. single-user multitasking in Linux;

Multi-task for a single user. For example, when we log on to the system with beinan and enter the system, I want to open gedit to write the document. However, when writing the document, I feel less music, so I opened xmms to make some music again. Of course, I couldn't even listen to some music, and MSN had to open it. I wanted to know what some of my colleagues are doing now. In this way, when I log on with the beinan user, run gedit, xmms, MSN, And the fcitx input method. In this case, a beinan user executes several tasks to complete the work. Of course, beinan is a user, others can log on remotely and do other work.


2. LINUX multi-user and multi-task;

Sometimes many users use the same system at the same time, but not all users must do the same thing, so there are multiple users and multiple tasks;

For example, linuxsir. the org server contains ftp users, system administrators, web users, and common users. At the same time, some may be visiting the forum, and some may be uploading software package management sites, for example, Luma or yuking is managing their home page system and FTP. At the same time, there may be system administrators who are maintaining the system. They use nobody users to browse the home page, the uploaded Software Package uses ftp users. The Administrator's maintenance or viewing of the system may use a common account or a root account with super permissions;Different users have different permissions. Different users are required to complete different tasks., You can also sayDifferent users may do different jobs.;

It is worth noting that multi-user multi-task operations are not performed by the keyboard and display of a single machine at the same time. Multiple users may log on remotely, for example, remote control of the server, anyone with user permissions can perform operations or access on the website;


3. User Role differentiation;

Users are divided into roles in the system. In Linux, permissions and tasks are different because of different roles; it is worth noting that the user's role is identified by uid, especially uid. In system management, the system administrator must stick to the unique characteristics of uid;

Root User: The system is unique and real. You can log on to the system, operate any files and commands in the system, and have the highest permissions;
Virtual users: These users are also known as pseudo users or fake users. They are differentiated from real users. Such users do not have the ability to log on to the system, but are indispensable users for system operation, for example, bin, daemon, ADM, FTP, mail, etc. All these users are owned by the system rather than those added later. Of course, we can also add virtual users;
Ordinary real users: These users can log on to the system, but can only operate the contents of their home directories; limited permissions; these users are added by the system administrator;


4. Security of multi-user operating systems;

Multi-user systems are more convenient for system management. From a security perspective, the multi-user management system is more secure. For example, if a file under a beinan user does not want other users to see it, just set the file permissions, only one beinan user can read, write, and edit data. In this way, only one beinan user can operate on its private files. Linux is the best performing solution for multiple users, linux can protect the security of every user, but we also have to learn about Linux as a secure system. If there is no security-aware administrator or management technology, such a system is not secure.

From the server point of view, the system security under multiple users is also the most important. For Windows operating systems that we commonly use, the system's capability of permission management can only be said to be general, there is no way to compare with Linux or Unix systems;


2. Concepts of user and group;

1. User concept;

Based on our understanding of multiple users in Linux, we understand that Linux is a real multi-user operating system, so we can build several users in Linux ). For example, our colleague wants to use my computer, but I don't want him to log on with my user name, because my user name contains information and information (that is, private content) that he does not want others to see) in this case, I can create a new user name for him to use the user name I opened, which is in line with the operational rules from the computer security perspective;

Of course, the concept of user is not just that. in Linux, there are still some users who are used to complete specific tasks, such as nobody and FTP. We access linuxsir. org's webpage program is a nobody user. FTP or nobody is used for anonymous ftp access. If you want to know some Linux accounts, see/etc/passwd;


2. Concepts of user groups;

A user group is a collection of users with the same features. For example, sometimes we want to allow multiple users to have the same permissions, for example, to view or modify a file or execute a command, we need a user group. We define all users to the same user group. By modifying the permissions of files or directories, the user group has certain operation permissions, so that users under the user group have the same permissions on the file or directory. This is achieved by defining the group and modifying the file permissions;

For example, in order for some users to have the permission to view a document, such as a timetable, the person who writes the timetable must have the permission to read and write the document, we want some users to know the contents of this Schedule without modifying them. Therefore, we can place these users into a group and modify the permissions of this file to make the user group readable, in this way, each user in the user group is readable;

The ing between users and user groups is one-to-one, multiple-to-one, one-to-many, or multiple-to-many;

One-to-one: a user can be a unique member of a group;
Multiple-to-one: multiple users can be members of a unique group and cannot belong to other user groups. For example, beinan and linuxsir users only belong to beinan user groups;
One-to-multiple: a user can be a member of multiple user groups. For example, beinan can be a member of the root Member, linuxsir user group, or ADM user group;
Many-to-many: multiple users correspond to multiple user groups, and several users can belong to the same group. In fact, the many-to-many relationship is the expansion of the first three. I have understood the three above, this article can also be understood;


3. configuration files, commands, or directories related to users and user groups;

1. configuration files related to users and groups;


1) configuration files related to users;

/Etc/passwd Note: user configuration file;
/Etc/shadow Note: User shadow password file;


2) configuration files related to user groups;

/Etc/group Note: User Group configuration file;
/Etc/gshadow Note: shadow file of the user group;


2. Tools or commands for managing users and groups;


1) Tools or commands used to manage users;

Useradd Note: Add a user
Adduser Note: Add a user
Passwd Note: set a password for the user
Usermod Note: to modify user commands, you can use usermod to modify the logon name and user's home directory;
Pwcov Note: Synchronize users from/etc/passwd to/etc/shadow
Pwck Note: pwck verifies whether the content of the user configuration file/etc/passwd and/etc/shadow is legal or complete;
Pwunconv Note: it is the vertical reverse operation of pwcov. It is to create/etc/passwd from/etc/shadow and/etc/passwd, and then delete the/etc/shadow file;
Finger Note: Tools for viewing user information
Id Note: view the UID, GID, and user group of the user.
Chfn Note: Change User information tool
Su Note: User Switching Tool
Sudo Note: sudo uses another user to execute commands (execute a command as another user), Su is used to switch users, and then the user to complete the corresponding tasks through the switch, however, sudo can directly execute the following commands. For example, sudo can execute root authorization without the root password. Only root can execute the corresponding commands; however, you must edit/etc/sudoers through mongodo;
Except do note: visodo is the command for editing/etc/sudoers. You can also use VI to edit/etc/sudoers;
Sudoedit Note: similar to the sudo function;


2) tools or commands used to manage user groups;

Groupadd Note: Add a user group;
Groupdel Note: delete a user group;
Groupmod Note: Modify user group information
Groups Note: displays the user group to which the user belongs.
Grpck
Note: Use the/etc/group and/etc/gshadow file content to synchronize or create/etc/gshadow. If/etc/gshadow does not exist, create it;
Grpunconv Note: Use the/etc/group and/etc/gshadow file content to synchronize or create/etc/group, and then delete the gshadow file;


3./etc/skel directory;

The/etc/skel directory is generally the directory for storing User Startup files, which is controlled by the root permission. When we add users, files in this directory are automatically copied to the Home Directory of the newly added user. Files in the/etc/skel directory are hidden files, which are similar. file Format. You can modify, add, or delete files in the/etc/skel directory to provide users with a unified, standard, and default user environment;

[Root @ localhost beinan] # ls-La/etc/skel/
Total usage 92
Drwxr-XR-x 3 Root 4096 August 11 23:32.
Drwxr-XR-x 115 Root 12288 October 14 13:44 ..
-RW-r -- 1 Root 24 00:15. bash_logout May 11
-RW-r -- 1 Root 191 May 11 00:15. bash_profile
-RW-r -- 1 Root 124 May 11 00:15. bashrc
-RW-r -- 1 Root 5619. canna
-RW-r -- 1 Root 438 May 18 15:23. emacs
-RW-r -- 1 Root 120 May 23 05:18. gtkrc
Drwxr-XR-x 3 Root 4096 August 11 23:16. KDE
-RW-r -- 1 Root 658 2005-01-17. zshrc

Files in the/etc/skel directory are generally copied to the Home Directory of the newly added user when we use the useradd and adduser commands to add a user; if we add a user by modifying/etc/passwd, we can create the user's home directory and copy the files under/etc/skel to the user's home directory, then, chown is used to change the owner of the new user's home directory;

4./etc/login. defs configuration file;

/Etc/login. the defs file is a plan for creating a user, such as whether to use the home directory, the UID and GID range, and the user's validity period when creating a user, this file can be defined by root;

For example, the/etc/logins. defs file content of Fedora;

# * Required *
# Directory where mailboxes reside, _ or _ name of file, relative to
# Home Directory. If you _ Do _ define both, mail_dir takes precedence.
# Qmail_dir is for Qmail
#
# Qmail_dir maildir
Mail_dir/var/spool/mail Note: when creating a user, you must create a user mail file in the/var/spool/mail directory;
# Mail_file. Mail

# Password aging controls:
#
# Pass_max_days maximum number of days a password may be used.
# Pass_min_days minimum number of days allowed between password changes.
# Pass_min_len minimum acceptable password length.
# Pass_warn_age Number of days warning given before a password expires.
#
Pass_max_days 99999 note: the maximum number of days for a user's password to expire;
Pass_min_days 0 note: the minimum number of days between password changes;
Pass_min_len 5 Note: Minimum Password Length;
Pass_warn_age 7 Note:

#
# Min/max values for automatic uid Selection in useradd
#
Uid_min 500 note: The minimum uid is 500, that is, when a user is added, the UID starts from 500;
Uid_max 60000 Note: The maximum uid is 60000;

#
# Min/max values for automatic GID Selection in groupadd
#
Gid_min 500 note: GID starts from 500;
Gid_max 60000

#
# If defined, this command is run when removing a user.
# It shoshould remove any at/cron/print jobs etc. Owned
# The user to be removed (passed as the first argument ).
#
# Userdel_cmd/usr/sbin/userdel_local

#
# If useradd shoshould create home directories for users by default
# On RH systems, we do. This option is ored with the-M flag on
# Useradd command line.
#
Create_home Yes Note: whether to create the user's home directory requires creation;


5./etc/default/useradd file;

The rule file when adding a user through useradd;

# Useradd defaults File
Group = 100
Home =/home Note: Create the Home Directory of the user in/home;
Inactive =-1 Note: whether to enable account expiration and suspension,-1 indicates not to enable;
Expire = Note: the end date of the account. If this parameter is not set, the account is not enabled;
Shell =/bin/bash Note: shell type used;
SKEL =/etc/skel Note: by default, the default file storage location of the user's directory is added. That is to say, when adduser is used to add users, the files in the user's home directory are, all of them are copied from this directory;


Postscript:

There are so many management contents about users and groups) management is almost the same. Because users and user groups are associated with file and directory permissions, therefore, operations on the file and directory permissions will be written into an independent document;

Related Article

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.