In linux, add users and grant root permissions. in linux, grant root permissions.

Source: Internet
Author: User

In linux, add users and grant root permissions. in linux, grant root permissions.
1. Add a user. First, use the adduser command to add a common user. The command is as follows:
# Adduser tommy
// Add a user named tommy
# Passwd tommy // change the password
Changing password for user tommy.
New UNIX password: // enter the New password here
Retype new UNIX password: // enter the new password again
Passwd: all authentication tokens updated successfully.
2. Grant root permissions
Method 1: Modify the/etc/sudoers file, find the following line, and remove the comment (#).
# Allows people in group wheel to run all commands
% Wheel ALL = (ALL) ALL
Then modify the user and make it belong to the root group (wheel). The command is as follows:
# Usermod-g root tommy
After modification, you can log on to the system using the tommy account and run the su-command to obtain the root permission.

Method 2: Modify the/etc/sudoers file, find the following line, and add a line under root, as shown below:
# Allow root to run any commands anywhere
Root ALL = (ALL) ALL
Tommy ALL = (ALL) ALL
After the modification, you can log on to the system using the tommy account and run the sudo-command to obtain the root permission.

Method 3: Modify the/etc/passwd file, find the following line, and change the user ID to 0, as shown below:
Tommy: x: 0: 33: tommy:/data/webroot:/bin/bash

I. User Account Management in Linux
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.
1. Add a new user account and use the useradd command,
Adding a user account adds a record to a new user in the/etc/passwd file and updates other system files, such as/etc/shadow and/etc/group.
Linux provides the integrated system management tool userconf, which can be used to manage user accounts in a unified manner.
Syntax:
Useradd option Username
Semantics:
-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: Specify 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.
User name specifies the login name of the new user.
Example 1:
$ Useradd-d/usr/sam-m sam
Meaning:
This command creates a user sam,
The-d and-m options are used to generate a main directory/usr/sam for the logon sam (/usr is the parent directory of the default user main directory ).
Example 2:
$ Useradd-s/bin/sh-g group-G adm, root gem
Meaning:
This command creates a new user gem. the user's logon Shell is/bin/sh (sometimes/bin/bash ),
It belongs to the group user group and also to the adm and root user groups. The group user group is the main group.
Run the following command to create a user group:
$ Groupadd group
$ Groupadd adm

2. delete an account
If a user's account is no longer in use, it can be deleted from the system.
To delete a user account, you must delete the user record in system files such as/etc/passwd. If necessary, delete the user's home directory.
Syntax:
Userdel option Username
Option:
-R: Delete the user's home directory together.
Example 1:
$ Userdel-r sam
Meaning:
This command deletes records of user sam in system files (mainly/etc/passwd,/etc/shadow,/etc/group,
Delete the user's home directory.

3. Modify an account
Modifying a user account is to change the user's attributes, such as the user ID, main directory, user group, and logon Shell.
Use the usermod command to modify the information of an existing user.
Syntax:
Usermod option Username
Option:
Including-c,-d,-m,-g,-G,-s,-u, and-o,
The meanings of these options are the same as those in the useradd command. You can specify a new resource value for the user.
In addition, some systems can use the following options:
-L the new user name specifies a new account, changing the original user name to the new user name.
For example:
$ Usermod-s/bin/ksh-d/home/z-g developer sam
Meaning:
This command sets the user sam's:
Log on to the Shell and change it to ksh,
Change the main directory to/home/z,
The user group is changed to developer.

4. Add a working group for existing users
Usermod-G groupname username
Or: gpasswd-a user group

5. User Password Management
An important part of user management is the management of user passwords.
A user account has no password when it was created, but is locked by the system and cannot be used. It can only be used after a password is specified, even if it is null.
The Shell command used to specify and modify the user password is passwd.
Super Users can specify passwords for themselves and other users. Common users can only use them to modify their own passwords.
Syntax:
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.
If the default user name is used, modify the password of the current user.
For example:
Assume that the current user is sam,
The following command modifies the user's password:
$ Passwd
Old password :******
New password :*******
Re-enter new password :*******
For Super Users,
The password of any user can be specified in the following form:
$ Passwd sam
New password :*******
Re-enter new password :*******

When a common user modifies his or her own password,
The passwd command will first ask for the original password, and then ask the user to enter the new password twice after verification,
If the two passwords are the same, the password is assigned to the user;
When a Super User specifies a password for the user, the original password is not required.

For the sake of system security, users should choose complicated passwords,
For example, it is best to use an 8-digit long password that contains uppercase letters, lowercase letters, and numbers, and should be different from the name and birthday.
Example 1:
When you specify a blank password, run the following commands:
$ Passwd-d sam
Meaning:
This command deletes the password of the user sam, so that the system will not ask for the password during the next logon.
The passwd command can also use the-l (lock) option to lock a user so that the user cannot log on. For example:
Example 2:
$ Passwd-l sam

2. User Group Management in Linux
Each user has a user group. The system can centrally manage all users in a user group.
Different Linux systems have different user group rules,
For example, a user in Linux belongs to a user group with the same name as a user group, and this user group is created simultaneously when a user is created.
User Group management involves adding, deleting, and modifying user groups. The addition, deletion, and modification of a group are actually updates to the/etc/group file.
1. Add a new user group to use the groupadd command.
Syntax:
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.
Example 1:
$ Groupadd group1
Meaning:
This command adds a new group group1 to the system. The Group ID number of the new group is added with 1 on the basis of the current largest group ID number.
Example 2:
$ Groupadd-g 101 group2
Meaning:
This command adds a new group group2 to the system and specifies that the Group ID of the new group is 101.

2. If you want to delete an existing user group, use the groupdel command.
Syntax:
Groupdel User Group
Example 1:
$ Groupdel group1
Meaning:
This command deletes group group1.

3. Run The groupmod command to modify the attributes of a user group.
Syntax:
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.
Example 1:
$ Groupmod-g 102 group2
Meaning:
This command changes the group ID of group group2 to 102.
Example 2:
$ Groupmod-g 10000-n group3 group2
Meaning:
This command changes the ID of group group2 to 10000 and the group name to group3.

4. If a user belongs to multiple user groups at the same time, the user can switch between user groups to have permissions for other user groups.
After logging on, you can use the newgrp command to switch to another user group. The parameter of this command is the target user group.
For example:
$ Newgrp root
Meaning:
This command switches the current user to the root user group, provided that the root user group is indeed the user's main group or additional group.

Similar to user account management, user group management can also be completed through integrated system management tools.

Source: http://blog.csdn.net/stormbjm/article/details/9086163


Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.