码迷,mamicode.com
首页 > 系统相关 > 详细

Linux基础知识part2

时间:2017-05-24 16:07:19      阅读:332      评论:0      收藏:0      [点我收藏+]

标签:vim   删除   模板   进程   linux基础知识   chmod   tom   user   用户名   

继续上一节,这次主要是用户和权限的一些知识点。

命令创建用户:useradd

手动创建用户:

/etc/passwd

/etc/shadow

/etc/gshadow

/home/用户名/

/var/spool/mail

id user 查看user用户个人信息。

用户家目录的隐藏文件模板  /etc/skel

ls -ld 查看目录详细信息

chown -R oldboy:oldboy /home/oldboy 递归更改

 

 

家目录下环境配置文件
env 查询环境变量
set 查询所有变量
环境变量可以被子进程继承 export b=2
自定义变量不能被子进程继承 a=1

环境配置文件(每个用户家目录下都存在)
.bash_history 保存用户的历史命令,当用户退出时保存到文件
.bash_logout 保存用户退出时执行的命令
.bashrc 保存用户别名 (开启新的终端就可以读取该文件)
.bash_profile 保存用户搜索命令的位置

.bashrc shell级别环境变量配置文件
.bash_profile 登录级别环境变量配置文件

su - 登录级别切换
su shell级别切换

全局环境配置文件
/etc/bashrc
/etc/profile

加载顺序
/etc/profile
.bash_profile
.bashrc
/etc/bashrc

定义变量文件顺序
/etc/profile1
/etc/profile2
.bash_profile1
.bashrc1
/etc/bashrc1
/etc/bashrc2
.bashrc2
.bash_profile2

权限(基本权限和高级权限)
[root@localhost ~]# ls -l install.log
-rw-r--r-- 1 robin upup 39751 05-23 11:15 aa.txt
rwx | rwx | rwx
robin upup other
uid=0----->uid=robin----->group=upup----->other

对于文件 r--------cat head tail....
w--------vim,gedit,vi,> >>
x--------执行./ 绝对路径
对于目录 r--------ls r-x查看目录下文件信息
w--------mkdir touhc rm rwx
x--------cd
user u
group g
other o

chmod u+r file/dir
chmod u+r,g+w file/dir
chmod ug-rw file/dir
chmod ugo+rwx file/dir
chmod a+rwx file/dir

chmod u=r file/dir
chmod u=r,g=w file/dir
chmod uo=rw file/dir
chmod ugo=rwx file/dir
chmod a=rwx file/dir

/ rwxr-xr-x 755
/etc/ rwxr-xr-x 755
/usr/ rwxr-xr-x 755
/var/ rwxr-xr-x 755
/tmp rwxrwxrwt 1777
/etc/shadow r-------- 400
/etc/passwd rw-r--r-- 644
/home/robin rwx------ 700
/root rwxr-x--- 750
root创建文件默认权限 rw-r--r-- 644
root创建目录默认权限 rwxr-xr-x 755
普通用户创建文件默认权限 rw-rw-r-- 664
普通用户创建目录默认权限 rwxrwxr-x 775

r------4 w------2 x-----1
777
rwxr----x 741 123--x-w--wx
r-x-wx-w- 532 456r--r-xrw-

默认权限计算方法
666 023
110110110 000010011
111101100 111101100
110100100
644

chmod -R 777 /test

修改拥有者所属组
chown robin tt.txt
chgrp uplooking tt.txt
chown robin.uplooking tt.txt
chown .uplooking tt.txt
.=:
chown -R robin.uplooking dir/

练习:
创建用户tom和jerry
1.在/tmp目录下创建文件tt.txt
要求:
tt.txt权限设置为651 在改为rwxr----x
chmod 651 /tmp/tt.txt
chmod u=rwx,g=r,o=x /tmp/tt.txt

设置tt.txt文件拥有这tom所属组jerry
chown tom.jerry /tmp/tt.txt

2.根据以下要求设置拥有者和权限
在/tmp目录下创建目录test/,在test目录下创建文件aa.txt
tom可以读写文件aa.txt 不能删除
jerry 不可以读写文件aa.txt 可以删除

mkdir /tmp/test/
touch /tmp/test/aa.txt

/tmp/test/ jerry root rwxr-xr-x
/tmp/test/aa.txt tom root rw-r-----

 

主组附加组
robin robin robin,uplooking
/tmp/test rwxrwx--- root uplooking
robin能不能进去/tmp/test? 为什么?
可以 因为附加组有uplooking
进入后创建文件aa.txt 该文件 拥有者 所属组??
robin robin
如果该用户想创建属于uplooking组的文件 怎么做?
sg uplooking
robin uplooking robin,uplooking
tt.txt robin uplooking

高级权限
1.suid
必须作用于二进制可执行文件
chmod u+s file
作用:任何用户在执行拥有suid权限的命令时,都以该命令拥有者的身份执行

实验:
在不改变/etc/shadow权限的前提下,使普通用户robin可以使用cat查看/etc/shadow文件内容
which cat
chmod u+s /bin/cat
robin用户测试

2.sgid
必须作用于目录
chmod g+s dir
作用:任何用户在拥有sgid的目录下创建的文件,都要继承该目录的组

 

useradd -g job -G uplooking tom
useradd -g job -G uplooking jerry
useradd -g sal -G uplooking zorro
useradd -g sal -G uplooking shrek

/job zhb uplooking rwxrwsr-x

aa.txt tom job
tt.txt tom uplooking rw-r-----


3.sticky(t 冒险位 粘贴位)
必须作用于目录
chmod o+t dir
作用:任何用户在拥有t权限的目录下创建的文件,都属于该用户自己,其他人无权删除(root,目录拥有者)

 

Linux基础知识part2

标签:vim   删除   模板   进程   linux基础知识   chmod   tom   user   用户名   

原文地址:http://www.cnblogs.com/ArmoredTitan/p/6898980.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!