Add users under Linux and give root privileges

Source: Internet
Author: User

Transferred from: http://blog.csdn.net/stormbjm/article/details/9086163

1, add the user, first with the AddUser command to add a normal user, the command is as follows:

#adduser Tommy

Add a user named Tommy
#passwd Tommy//Change password changing password for user Tommy.
New UNIX Password://Enter your password here
Retype new UNIX Password://Enter password again
Passwd:all authentication tokens updated successfully.

2. Give root permission

Method One: Modify the/etc/sudoers file, locate the following line, remove the previous comment (#)

# # allows people in group wheel to run all commands
%wheel all= (All) all

Then modify the user to belong to the root group (wheel) with the following command:

#usermod-G root Tommy

After the modification, you can now log in with your Tommy account and then use the command su– to get root permission to operate.

Method Two: Modify the/etc/sudoers file, locate the following line, and add a line under root as follows:

# allow ROOT to run any commands anywhere
Root all= (All) all
Tommy All= (All) all

After the modification, you can now log in with your Tommy account and then use the command sudo– to get root permission to operate.

Method Three: Modify the/etc/passwd file, locate the following line, change the user ID to 0, as follows:
Tommy:x:0:33:tommy:/data/webroot:/bin/bash

I. Management of Linux system user accounts
The management of user accounts mainly involves the addition, modification and deletion of user accounts.
To add a user account is to create a new account in the system.
Then assign the user number, user group, home directory, and login shell resources to the new account.
The account you just added is locked and cannot be used.

1, add a new user account using the Useradd command,
Add a user account is in the/etc/passwd file to add a record for the new user, while updating other system files such as/etc/shadow,/etc/group and so on.
Linux provides an integrated system management tool, userconf, which can be used to manage user accounts uniformly.

Grammar:
Useradd option User Name
Semantic:
-C Comment Specifies an annotative description.
The-D directory specifies the home directory, and if this directory does not exist, the-m option can be used to create the master directory.
The-G user group specifies the user group to which the user belongs.
The-G User Group user group specifies the additional groups to which the user belongs.
-S Shell file specifies the user's login shell.
-u user number specifies the user's user number, and if you have the-o option, you can reuse the other user's identification number.
User name Specifies the login name of the new user.

Example 1:
$ useradd–d/usr/sam-m Sam
Interpretation:
This command creates a user Sam,
Where the-D and-m options are used to generate a home directory for the login Sam/usr/sam (/usr is the parent directory where the default user home directory resides).

Example 2:
$ useradd-s/bin/sh-g group-g adm,root Gem
Interpretation:
This command creates a new user gem, the user's login shell is/bin/sh (sometimes with/bin/bash),
It belongs to group user groups and also to the ADM and root user groups, where group user groups are their primary groups.

New user group Commands available:
$ Groupadd Group
$ Groupadd ADM

2. Delete Account
If a user's account is no longer in use, it can be removed from the system.
Deleting a user account is to delete the user record in the system files such as/etc/passwd, and delete the user's home directory if necessary.
Grammar:
Userdel option User Name
Options:
-R, delete the user's home directory together.

Example 1:
$ userdel-r Sam
Interpretation:
This command deletes the records of the user Sam in the system files (mainly/etc/passwd,/etc/shadow,/etc/group, etc.),
Delete the user's home directory at the same time.

3, modify the account
Modify user account is based on the actual situation to change the user's relevant attributes, such as user number, home directory, user group, login shell and so on.
Modify the information for an existing user using the Usermod command.
syntax:
     usermod Option user name
option:
    includes-C,-D,-M,-G,-G,-S, -U and-O, etc.,
    The meaning of these options is the same as the options in the Useradd command, you can specify a new resource value for the user.
In addition, some systems can use the following options:
   -L new user name   Specify a new account to change the original user name to a new one.

For example:
$ usermod-s/bin/ Ksh    -d/home/z    -g developer    sam
This command will user Sam's:
login shell modified to Ksh,
main directory changed to/home/z,  
user group changed to developer.

4. Increase the Working Group for existing users
USERMOD-G groupname username

Or: Gpasswd-a user Group

5, the user password management
An important part of user management is the management of user passwords.
The user account has just been created without a password, but is locked by the system, cannot be used, it must be given a password before it can be used, even if a blank password is specified.
The shell command that specifies and modifies the user's password is passwd.
A superuser can specify a password for himself and another user, and a normal user can only use it to modify his or her password.
syntax:
     PASSWD Option user name
options:
     -u     password unlock.
     -d     make account no password.
     -f     Forcing the user to change the password the next time they log on.
    If the default user name, modify the current user's password.

For example:
Assuming the current user is Sam,
$ passwd
old password:******
new password:*******

Re-enter New password:*******

If you are a superuser,
You can specify the password for any user in the following form:
$PASSWD Sam
New password:*******
Re-enter New password:*******

When an ordinary user modifies his or her password,
passwd command will first ask the original password, verify and then ask the user to enter two times the new password,
If the password entered in two times is consistent, the password is assigned to the user;
When a superuser assigns a password to the user, it does not need to know the original password.

For the sake of system security, users should choose a more complex password,
For example, it is best to use a 8-bit long password that contains uppercase, lowercase letters, and numbers, and should be different from names, birthdays, and so on.

For example 1:
When you specify an empty password for a user, the following forms of command are executed:
$PASSWD-D Sam
Interpretation:
This command removes the password for the user Sam so that the next time the user Sam logs on, the system will no longer ask for the password.

The passwd command can also lock a user with the-l (lock) option so that it cannot log on, for example:
For example 2:
$ passwd-l Sam

ii. Management of Linux system user groups
Each user has a user group, and the system can centrally manage all users in a single user group.
Different Linux systems differ from user groups,
If the user under Linux belongs to a user group with the same name, the user group is created at the same time as the user is created.
The management of user groups involves adding, deleting, and modifying user groups. The addition, deletion, and modification of a group is actually an update to the/etc/group file.

1. Add a new user group using the Groupadd command.
Grammar:
Groupadd Option User Group
Options:
-G GID Specifies the group identification number (GID) of the new user group.
-O is commonly used with the-G option, which means that the GID of the new user group can be the same as the GID of the user group already in the system.

Example 1:
$ groupadd group1
Interpretation:
This command adds a new group group1 to the system, and the group identification number of the new group is added 1 on the basis of the currently existing maximum group identification number.

Example 2:
$ groupadd-g 101 Group2
Interpretation:
This command adds a new group group2 to the system, specifying that the group identification number for the new group is 101.

2. If you want to delete an existing user group, use the Groupdel command.
Grammar:
Groupdel User Group

Example 1:
$ Groupdel group1
Interpretation:
This command removes the group group1 from the system.

3. Modify the properties of the user group using the groupmod command.
Grammar:
Groupmod Option User Group
Options:
-G GID Specifies a new group identification number for the user group.
The-O is used in conjunction with the-G option, and the user group's new GID can be the same as the GID of the user group already in the system.
-N New user Group change user group name to new name

Example 1:
$ groupmod-g 102 group2
interpretation:
Span style= "FONT-SIZE:14PX;" > This command modifies the group ID number of group group2 to 102.

$ groupmod–g 10000- n group3 group2
This command changes the group group2 identification number to 10000, The group name is modified to Group3.

4. If a user belongs to more than one user group at the same time, the user can switch between groups of users so that they have permissions to other groups of users.

For example:
$ newgrp root
Span style= "FONT-SIZE:14PX;" > definition:

http://www.libaqiang.com/?p=33001

Http://blog.chinaunix.net/uid-26000296-id-3496103.html

Add users under Linux and give root privileges (GO)

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.