Linux users, group accounts and permissions (study note 9), and linux Study Notes

Source: Internet
Author: User

Linux users, group accounts and permissions (study note 9), and linux Study Notes
I. User Classification

  • Super User: root
  • Common users: created by super users and administrators. Generally, they only have full permissions in their directories.
  • Program User:
2. User Account Management

Common commands:

Useradd: Add a user

Userdel: delete a user

Passwd: Set the User Password

Groupadd: Add a group account

Groupdel: deletes a group account.

Gpasswd: Add/delete group members

2.1,Useradd: Add a user

[root@model tar]# useradd  -e 20150222 test1       [root@model tar]# passwd test1Changing password for user test1.New password: BAD PASSWORD: it is too shortBAD PASSWORD: is too simpleRetype new password: passwd: all authentication tokens updated successfully.[root@model tar]# useradd test2
2.2,Userdel: delete a user

[root@model tar]# userdel test2 -r[root@model tar]# ls -l /home/total 4drwx------. 4 test1 test1 4096 Feb 20 02:25 test1[root@model tar]# 
2.3. papasswd: Set the User Password

[root@model tar]# passwd -S test1test1 PS 2015-02-19 0 99999 7 -1 (Password set, SHA512 crypt.)[root@model tar]# passwd -l test1Locking password for user test1.passwd: Success[root@model tar]# passwd -S test1test1 LK 2015-02-19 0 99999 7 -1 (Password locked.)[root@model tar]# passwd -u test1Unlocking password for user test1.passwd: Success[root@model tar]# passwd -S test1test1 PS 2015-02-19 0 99999 7 -1 (Password set, SHA512 crypt.)[root@model tar]# passwd -d test1Removing password for user test1.passwd: Success[root@model tar]# 
2.4. groupadd: Add a group account

 

[root@model ~]# groupadd class1[root@model ~]# useradd test2 -g class1 
2.5. groupdel: delete a group account 2.6. gpasswd: Add/delete group members

[root@model ~]# useradd test3[root@model ~]# gpasswd -a test3 class1Adding user test3 to group class1[root@model ~]# gpasswd -d test3 class1Removing user test3 from group class1[root@model ~]# groupdel class1[root@model ~]# 
2.7 user group Modification
Change User Group: usermod-g group_name user_name add user to another group: usermod-G group_name user_name modify group name: groupmod-n new_group_name old _ group_name
2.8 view the current user group
[root@model home]# groups root[root@model home]# 
2.9 modify user information

Command for modifying user information:
[Root @ local opt] # usermod parameter Username
Parameters:
-C description
-G group name: initial user group
-E Expiration Date Format: YYYY-MM-DD
-G group name: other user groups
-L modify user name
-L lock the account (add two exclamation marks (!) before the password string in the/etc/shadow file (!!))
-U unlock

Iii. Permissions
[root@model Documents]# ls -altotal 88drwxr-xr-x.  7 root root  4096 Feb 20 01:49 .dr-xr-x---. 28 root root  4096 Feb 18 07:00 ..-rw-r--r--.  1 root root    56 Feb 19 23:52 a.txtdrwxr-xr-x.  4 root root  4096 Feb 20 00:40 com-rw-r--r--.  1 root root   148 Feb 20 01:23 c.tar.gz-rw-r--r--.  1 root root    88 Feb 20 01:09 c.txt-rw-r--r--.  1 root root    30 Feb 20  2015 file1.txt.gz-rw-r--r--.  1 root root 34419 Feb 20 00:33 httpd.confdrwxr-xr-x.  3 root root  4096 Feb 20 01:49 tar-rw-r--r--.  1 root root    71 Feb 20  2015 testdrwxr-xr-x.  4 root root  4096 Feb 19 22:33 test1drwxr-xr-x.  2 root root  4096 Feb 19 22:32 test4-rw-r--r--.  1 root root   230 Feb 20 01:19 test4.tar.gzdrwxr-xr-x.  4 root root  4096 Feb 20  2015 tests[root@model Documents]# 

The column in the list is defined as follows:
[Permission attribute information] [connections] [owner] [owner user group] [size] [last modification time] [file name]

The permission attribute list contains 10 characters:
The first character represents the file type, and d is the directory-for common files l is the connection B is a storage Interface Device c is the keyboard, mouse, and other input devices
2, 3, and 4 characters indicate the owner's permissions, 5, 6, and 7 characters indicate the owner's permissions for the same group of users, and 8, 9, and 10 indicate other user permissions.

The second character indicates the owner's read permission. If the owner has the permission, the value is r. If the owner does not have the permission, the value is-
The third character indicates the owner's write permission. If the owner has the permission, the value is w. If the owner does not have the permission, the value is-
The fourth character indicates the owner's execution permission. If the owner has the permission, the value is x. If the owner does not have the permission, the value is-
The fifth character indicates the owner's read permission for users in the same group. If the owner has the r permission, the value is-
The sixth character indicates that the owner has the write permission for the same group of users. If the owner has the permission, the value w indicates that the owner has no permission, and the value-
The seventh character indicates that the owner has the permission to execute the same group of users. If the owner has the permission, the value is x. If the owner does not have the permission, the value is-
The eighth character indicates other non-same group read permissions. If you have the permission, the value is r. If you do not have the permission, the value is-
The ninth character indicates the write permission of other non-identical groups. If you have the permission, the value is w. If you do not have the permission, the value is-
The tenth character indicates the execution permission of other non-same groups. If you have the permission, the character is x. If you do not have the permission, the character is-

Iv. Permission Representation

Digit and character formats

R, w, and x can be represented by, 2, and 1 of the octal values respectively, indicating that numbers must be added to a combination. For example

 

V. Permission setting chmod 5.1. chmod [ugoa...] [+-=] [rwx] file or directory

Ugoa: For the user category, u represents the owner of the file, g represents the user in the user group where all files are located, o any other user, and a represents all users (u, g, o total)

+-=: Indicates the action for setting permissions. + indicates that the corresponding permissions are added.-Minus indicates that the corresponding permissions are missing. = indicates that only the corresponding permissions are set.

Rwx: character combination of permissions. It can be used in a single way or in combination, for example, r, w, x, rw, rx, wx,

5.2. chmod nnn File or directory

5.3 chmod-R Option

Add the-R option to set the subdirectories in the directory to the same permission.

Vi. Set File Ownership

Chown: You can set the owner and group.

Chgrp: Modify group only

Therefore, chown is often used

6.1. chown

Chown owner [: [group] file or directory

Separate them:

If you want to set a group separately, you need to: Group

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.