linux-- rights management and user management

Competence

check the detail information

ls -l

-   rw-  r--  r--  1 tom  root  0  Jun 20 00:02  apple.txt
1    2    3    4   5  6    7    8       9          10
#1  文件的类型
#[-:普通文件]
#[d:目录]
#[l:软链接]
#[c:字符设备(键盘,鼠标)]
#[b:快文件,硬盘]

如何修改test.py文件权限为700
    chmod 700 test.py

#2   表示文件/目录所有者权限
#3   文件/目录所在组的用户的权限
#4   文件/目录其它组的用户的权限
#-----[r:可读]
#-----[w:可写]
#-----[x:]
#-----[-:没有权限]

#5  
    #如果是文件,表示硬链接的数
    #如果是目录,表示目录的子目录的个数

#6  文件/目录所在用户
#7  文件/用户所在组
#8  文件的大小,单位:字节,,,如果是目录,显示4096
#9  文件/目录最后的修改时间
#10 文件/目录名

Administrative rights

Modify permissions

通过chmod指令,可以修改文件或者目录的权限

Use the +, -, = change permissions

#u:所有者(user)
#g:所有组(group)
#o:其他人(other)
#a:所有人(all)(u、g、o的总和)

chmod u=rwx,g=rx,o=x 文件目录名
#表示给所有者读、写、执行权限 ,给所有组读和执行权限,给其他人执行权限

chmod o+w 文件目录名
#表示给其他人添加写的权限

chmod a-x 文件目录名
#表示给所有人去除执行的权限

#案例
#1、给abc文件的所有者读写执行的权限,给所有组读执行权限,给其他组读执行权限
chmod u=rwx,g=rx,o=rx abc
#2、给abc文件的所有者除去执行的权限,增加所有组写的权限
chmod u-x,g+w abc
#3、给abc文件的所有用户添加读的权限
chmod a+r abc

Use the numeric change permissions

#规则 
r=4   #二进制 100
w=2   #二进制 010
x=1   #二进制 001
rwx=4+2+1=7 

chmod u=rwx,g=rx,o=x 文件目录名
#相当于
chmod 751 文件目录名

#案例:将/home/abc.txt文件的权限修改成rwxr-xr-x,使用数字的方式实现
chmod 755 /home/abc.txt

Group modify the file resides

chgrp newgroup file #改变文件的所有组

#案例
#1、将/home/abc.txt文件的所在组修改成bandit(土匪)
chgrp bandit /home/abc.txt
#2、将/home/kkk 目录下所有的文件和目录的所在组都修改成bandit(土匪)
chgrp -R bandit /home/kkk

User Management

1, Linux system is a multi-user multi-tasking operating system, a user want to use any system resources, must first apply for an account to the system administrator, and then log in as the account.

2, Linux users belong to at least one user group.

Add user

useradd [选项] 用户名    #[选择]是参数

useradd -d 新的用户名     #给新创建的用户指定家目录  ConterOS
useradd -m 新的用户名     #给新创建的用户指定家目录  Unbutu

#比如:
useradd -m yangxinhu    #创建了一个用户   并且home下会自动生成一个yangxinhu的目录

delete users

userdel 用户名   #删除用户  但是保存用户家目录
userdel -r 用户名  #删除用户  同时删除用户家目录

set password

passwd 用户名

change Password

passwd

View user

w     #查看用户列表

id 用户名  #查看指定用户信息

whoami      #查看当前用户名

who am i    #查看当前登录用户名

Switch User

su - 用户名

user group

Description: Similar to the role, the system can be unified management of multiple users have in common.

groupadd 组名

useradd -g 用户组 用户名   #增加一个用户的时候直接将他指定到一个组

Delete Group

groupdel 组名

Modify the user's group

usermod -g 用户组 用户名

Attribute of each file is determined by the character of the first portion 10 to the left

From left to right are represented by the numbers 0-9.

Bit 0 determine file types, positions 1-3 to determine the owner (owner of the file) have access to the file.

The first set 4-6 to determine the genus (group of users with the owners) have access to the file, 7-9 bits identify other users who have access to the file

Note the process ID of the user occupancy

Guess you like

Origin www.cnblogs.com/tangjian219/p/12088252.html