Linux_ubuntu command-User, rights management

Source: Internet
Author: User
Tags chmod file permissions

User is an important part of unix/linux system, user management includes user and group account management.

In the Unix/linux system, either by the local or remote login system, each system must have an account, and for different system resources have different use rights.

The root account in the Unix/linux system is typically used for system maintenance and management, and it has unrestricted access to all parts of the Unix/linux operating system.

In the Unix/linux installation process, many user accounts are created automatically, and these default users are called "Standard users".

In most versions of Unix/linux, it is not recommended to log into the system directly using the root account.

<1> View Current User: WhoAmI

WhoAmI This command user to view the user name of the current system's current account. System user information can be viewed through cat/etc/passwd.

Because system administrators often need to log on to the system with multiple identities, such as typically using a normal user login system, and then switch to the root identity of the SU command to manage the legacy. At this point, you can use WhoAmI to view the current user's identity.

<2> view logged in User: Who

The WHO command is used to view user information for all currently logged-on systems.

Common options:

Options meaning
-M or AM I Displays only the user name, logon terminal, and logon hours that run the WHO command
-Q or--count Only shows the user's login account and the number of logged-in users
-U Displays the user's last action to the current time interval after the logon time
-U or--heading Show Column headings

<3> sign Out of your account: Exit

If it is a graphical interface, exit the current terminal;

If you are using SSH telnet, log out of the login account;

If it is the logged-in user after the switch, exit will return to the previous login account.

<4> Switch Users: su

You can switch users by using the SU command, and you can add "-" after Su. The difference between the SU and su– commands is that Su-when switched to the corresponding user, will automatically convert the current working directory to the switched user home directory:

Note: If you have an Ubuntu platform, you need to add "sudo" before the command, and if you need an administrator to operate on some operations, Ubuntu does not need to switch to the root user to operate, just add "sudo". sudo is a tool under the Ubuntu platform that allows the system administrator to let ordinary users perform some or all of the root commands, reducing the login and administration time of the root user and improving security.

Command meaning
Su Switch to root user
Su Root Switch to root user
Su- Switch to the root user while switching directories to/root
Su-root Switch to the root user while switching directories to/root
Su Ordinary user Switch to normal user
Su-Ordinary users Switch to normal user while switching to the directory where the normal user is located
<5> Add, delete group accounts: Groupadd, Groupdel

Groupadd New group Account Groupdel group account cat/etc/group View user group

<7> Add user account: Useradd

Add a user account in Unix/linux you can use the AddUser or Useradd command, because the adduser command is a link to the Useradd command, so the two commands are in exactly the same format.

The Useradd command is used in the following format: useradd [parameters] New user account

Parameters meaning
-D Specifies the home directory when the user logs on to the system, and if this parameter is not used, the system automatically establishes a directory with the same name as the user name in the/host directory
-M Automatic Directory Creation
-G Specify Group name

Related instructions:

    • Linux each user must have a home directory, the home directory is the first login system, the user's default current directory (/home/users);
    • Each user must have a home directory, so when you create a user with Useradd, you must specify a home directory for the user;
    • The user's home directory is usually placed in the root directory of the home directory, the user's home directory and user name is the same;
    • If you do not specify a group name when creating a user, then the system automatically creates a group name that is the same as the user name.
Command meaning
useradd-d/HOME/ABC abc-m Create the ABC user, if the/HOME/ABC directory does not exist, the directory is created automatically, and the user belongs to the ABC Group
useradd-d/home/a a-g test-m Create a user name called a, home directory in/home/a, if the home directory does not exist, automatically create the home directory, while the user belongs to the test group
cat/etc/passwd View System Current user name
<8> Set User password: passwd

In Unix/linux, a superuser can use the passwd command to set or modify a user's password for a normal user. Users can also use the command directly to modify their own passwords without having to use the user name after the command.

<9> Delete users: Userdel
Command meaning
Userdel ABC (user name) Delete the ABC user, but do not automatically delete the user's home directory
USERDEL-R ABC (user name) Delete a user while deleting the user's home directory
<10> Modify file permissions: chmod

There are two ways to use chmod to modify file permissions: Alphabetic and digital.

Letter method: chmod u/g/o/a +/-/= rwx file

[u/g/o/a] meaning
U User represents the owner of the file
G Group indicates that the owner of the file belongs to the same group, which is the user group
O Other means other than the other person
A All means that all three of them are
[ +-= ] meaning
+ Increase permissions
- Revoke permissions
= Set permissions
rwx meaning
R Read means readable, and for a directory, without r permission, it means that the contents of this directory cannot be viewed through LS.
W Write means writable, and for a directory, without the W permission, it means that a new file cannot be created under the directory.
X Excute is executable, and for a directory, if there is no X permission, it means that the directory cannot be accessed by CD.

chmod o+w file adds write permissions to the other users of files:

The chmod u-r file subtracts the Read permission from the owner of files:

chmod g=x file Sets the permissions for the same group of users as files to be executable while removing read and Write permissions:

Digital method: "rwx" These permissions can also be replaced by numbers

Letters Description

r| Read permission, the number code is "4" w| Write permission, the number code is "2" x| execute permission, the number code is "1"-| does not have any permission, the number is codenamed "0"

If executed: chmod u=rwx,g=rx,o=r filename is equivalent to: chmod u=7,g=5,o=4 filename

chmod 751 File:

    • File owner: Read, write, execute permissions
    • Same group of users: Read, execute permissions
    • Other users: Permissions to execute

chmod 777 File: All users have read, write, execute permissions

Note: If you want to recursively add the same permissions to all directories, you need to add the parameter "-R". Example: chmod 777 test/-R All files in the recursive test directory plus 777 permissions

<11> Modify file Owner: Chown

<12> modify file belongs to group: CHGRP

<11> Modify file Owner: Chown

Linux_ubuntu command-User, rights management

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.