Linux's user / group management and task scheduling learning summary

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/Weixiaohuai/article/details/90937799

I. Introduction

This paper will summarize the Linux user management, group management and task scheduling related commands and theoretical knowledge in order to better understand the internal management of Linux users and how to use Linux task scheduling time to complete a task, such as scheduled backup databases Wait.

Second, group management

In Linux, any user must belong to at least one user group , a user can belong to multiple groups at the same time. There are several corresponding concept in Linux user management, group management

[A] user's home directory: all the user's home directories are located in the root directory / home folder below , have their home directory corresponding to the user's home directory, the user name is the name of the file folder, suppose a user wsh, then it's home directory is / home / wsh.

 

[B] owner of the file: Files are generally creator, who created it, then who is the owner of the file, assuming wsh test1.txt created a file, then the file owner is test1.txt wsh.

ls -ahl: view the file owner.

chown wsh a.txt: a.txt owner of the file into wsh user.

 

[C] file's group: When a user creates a file, the default user group creator of the file where is the group to which the file is located. Assume wsh to create a file a.txt, wsh where the group test, then the file is located a.txt group test.

ls -alh: view the file's group

chgrp test1 a.txt: change the file's group

 

[D] file other groups: In addition to the owner and the user's group of files, other users of the system are the other group of files

[E] group / user created: groupadd xxx group name / useradd xxx User

groupadd g1: Create a group g1

groupdel g1: Delete group g1

useradd weixiaohuai:创建用户weixiaohuai

useradd -g g2 wangwu : 创建用户的时候同时指定其所在的用户组

userdel zhangsan:删除用户zhangsan,但是不删除用户的家目录。

userdel -r lisi:删除用户lisi,并且删除家目录。

id weixiaohuai:查看用户weixiaohuai信息

usermod -g test1 weixiaohuai :修改weixiaohuai用户所在的组为test1。

su - :由普通用户切换到超级管理员用户,需要输入管理员密码。

su - wsh:由管理员用户切换到普通用户登录,高权限用户切换到低权限用户不需要重新输入密码。

exit:退出登录

passwd wsh:修改用户wsh的登录密码。

三、权限管理

【a】权限基本介绍

-rw-r--r--. 1 root root    0 Jun  2 21:51 test111.txt

下面依次对上面展示的进行介绍,注意权限rwx都是每三位为一组。  r:读     w:写      x:可执行
-:表示文件的类型,-表示普通文件  d表示目录等;

rw-:文件所有者所拥有的对改文件的权限(读、写);

r--:文件所在组所拥有的对改文件的权限(读);

r--:其他组所拥有的对改文件的权限(读);

Jun  2 21:51:最后修改时间;

test111.txt:文件名称

 

【b】rwx权限简介

(1) 作用到文件上:

r:表示可以读取、查看该文件;

w:表示可编辑该文件;

x:表示可执行;

(2) 作用到目录上:

r:表示可以读取、查看该目录内的文件内容;

w:表示可对该目录删除、创建;

x:表示可进入该目录;

-rwxr-xr--. 1 root root    0 Jun  4 20:43 b.txt
rwx:具有读、写、可执行权限;

r-x:具有读、可执行权限;

r--:只有读权限;

当然,工作中一般都是用数字来表示这些权限,方便容易记住。rwx各自对应下面的数字,

r = 4

w =  2 

x = 1 

那么rwx = 4 + 2 + 1 = 7;  r-- = 4 + 0 + 0 = 4; rw-  = 4 +2 = 6,以此类推。

 

【c】修改权限

chmod:用于修改文件或者目录的权限。主要有两种方式,如下

(1) .第一种方式:通过u/g/o设置

u:所有者       g:所在组的用户    o:其他组的用户

chmod u=rwx,g=r,o=rw a.txt:给a.txt文件所有者rwx(读写可执行)权限,所在组r(只读)权限,其他组用户rw(读写权限);

chmod g+w a.txt :给a.txt文件所在组增加可写(w)权限;

chmod u-x a.txt:给a.txt文件所有者去除可执行(x)权限;

(2). 第二种方式:通过数字进行设置(推荐使用该方式)

chmod 744 a.txt : rwx = 7  r=4   r=4,即给a.txt用户所有者可读可写可执行权限、所在组可读权限,其他组用户可读权限。

chmod 400 a.txt:同理

四、任务调度

在实际工作中,这一块主要是拿来定时执行一些我们的shell脚本或者程序,通常是定时备份数据库等等场景。Linux中,通过设置crontab进行定时任务的设置。

【a】定时任务时间参数介绍

*/1 * * * * 

第一个*/1:表示一小时中的第几分钟;

第二个*:表示一天中的第几小时;

第三个*:表示一个月中的第几天;

第四个*:表示一年中的第一个月;

第五个*:一周当中的星期几;

 

【b】示例:每隔一分钟将ls -l / 的信息输出到task1.txt中

crontab -e

*/1 * * * * ls -l >>  /test/task1.tx

我们可以使用tail -f task1.txt实时监控文件内容的变化:

Of course, if the timing task more responsible, we need to schedule content to write a shell script, and then call in the crontab execute shell, shell programming and other summary back to the time will do an example to explain.

[C] crond related commands

crontab -r: terminate the task scheduling

crontab -l: what tasks have to query the current scheduling

 

V. Summary

This paper summarizes the Linux users, manage groups, permissions and describes how to use Linux timing scheduling, command relatively high, take time to look at the practical operation, in order to deepen understanding of these commands, this is only author in the learning process Some summary, I hope you can help.

 

 

Guess you like

Origin blog.csdn.net/Weixiaohuai/article/details/90937799
Recommended