笔记3

1.用户权限下放 sudo

 1)超级用户下放权限配置

vim /etc/sudoers   (进入配置文件)    //无语法检测

visudo  //编辑文件/etc/sudoers,但有语法检测

2)文件内容编辑:

@@

99 ## Allow student to run useradd in my host

100 student   desktop126.example.com=(root)  /usr/sbin/useradd

@@

 

注意:

  怎么去查看主机名? hostname

  怎么查看命令useradd所在的文件? which useradd

  怎么实现第一次无密码执行命令? NOPASSWD: /usr/sbin/useradd

 

3)下放权限的用户怎么使用

  sudo useradd hello

 

2.用户认证信息的控制

 1)一个文件:

/etc/passwd  密码文件   第二列 密码(隐藏在shadow)

/etc/shadow  密码

 

 (user:passwd:最后一次修改密码时间:最短有效期:最长有效期:警告期:非活跃期:失效期:保留)

 

 查找文件帮助   man 5+文件名(不是绝对路径)

       man 5 shadow

 一步设置密码   echo

 

2)两个命令:

chage(-d,-m,-M,-W,-I,-E)

passwd(-S,-d,-l,-u,-n,-x,-w,-i)

 

vim /etc/passwd 直接修改   第三列为0(每次登陆修改密码)

 

3. 查看文件属性(详细信息)

 

ls -l /mnt     查看目录中内容权限   ll(ls - l)

ls -ld /mnt    查看目录权限

 

-rw-r--r-- 1 root root 0 Dec 30 21:43 hello

drwxr-xr-x 2 root root 6 Dec 30 21:44 test

 

第一个字节:代表文件类型

  -              //普通文件

d //目录

 s //socket文件

 l //链接文件File: /home/kiosk/Desktop/day03.md

 

  u: 文件所有人对于该文件的权限

  g: 文件所属组成员对该文件所拥有的权限

 o: 其他人对文件所拥有的权限

 

 r(read):读权限

 对于文件:cat

  对于目录:ls

 

 w(write):写权限

  对于文件:vim,gedit

  对于目录:touch/mkdir,rm/rmdir

 

 x(exec):执行权限

 对于文件:普通文件不需要执行权限;

 对于目录:能否cd到该目录

 

4.修改文件所有人和所属组

 

chown

chown student 文件

chown student.student 文件

chown student 目录 -R

chown student:student 目录 -R

chown --reference=find.all file

//参考find.all修改file文件的所有人和所有组

chgrp

chgrp student 文件

chgrp student 目录 -R

chgrp --reference=find.all file

 

5.修改文件权限

 

1)通过字符方式修改

    chmod    <u|g|o><+|-|=><r|w|x>  目标

     chmod u+r,g-w,o=r /mnt/file

   chmod u=rw,g=r,o-r /mnt/file

 

2)通过数字方式修改

 

  r:4 w:2 x:1

 

7:rwx 6:rw- 5:r-x 4:r--

3:-wx 2:-w- 1:--x 0:---

 

u:rwx g:rx o:-

 

6.系统默认权限的设定

 

umask值:系统默认要去掉的权限;

 注意:默认普通文件不需要执行权限。

 

- 从系统安全角度来看,umask越大越安全。

- 如何设定umask

/etc/bashrc

/etc/profile

 

7.特殊权限

 

1). o+t权限: sticky  粘制位

 

效果:只针对于目录,当目录上有o+t的权限时,所有用户在该目录下均可创建文件,但只有文件所有人和root用户可以删除该目录下的文件。

 

设定方式:

chmod o+t 目录

chmod 1777 目录

     7*** 任意权限

        0    任意

 

在系统中的应用:

[root@desktop126 ~]# ll -ld /tmp/

drwxrwxrwt. 28 root root 4096 Dec 31 01:39 /tmp/

 

2). u+s权限:suid  冒险位

 

效果:只针对于二进制可执行文件,该命令发起的程序是以该命令所有人的身份去执行。

 

设定方式:

chmod u+s 二进制可执行文件

chmod 4755 二进制可执行文件

 

在系统中的应用:

[root@desktop126 ~]# ll /usr/bin/passwd

-rwsr-xr-x. 1 root root 27832 Jan 29 2014 /usr/bin/passwd

[root@desktop126 ~]# ll /etc/shadow

---------- 1 root root 1493 Dec 30 21:37 /etc/shadow

 

3). g+s权限:强制位

 

效果:

针对二进制可执行文件:该命令发起的程序是以该命令所有组的身份去执行;

针对目录:目录新建文件的所属组与该目录的所有组保持一致;

 

设定方式:

chmod g+s  文件|目录

chmod 2755 文件|目录

 

touch     创建文件在创建文件所在用户名下

chmod g+s /bin/touch    使创建文件在所属组名下

 

8.ACL权限:  file access control list  (文件系统访问控制列表)

1)如何查看文件是否有acl权限?

  ll /etc/passwd

-rw-r--r--<.> 1 root root 2173 Jan 6 21:08 /etc/passwd  //注释:第11位为.时代表没有acl权限;为+时代表有acl权限。

2)setfacl

setfacl -m <u|g|m>:<username|groupname>:rwx 文件名 //添加或者修改acl权限

setfacl -m d:<u|g|m>:<username|groupname>:rwx 目录名 //添加或者修改目录下新建文件默认acl权限

   例子:

setfacl -m u:user2:rw hello //指定user2用户对hello文件有读写权限

setfacl -m g:user2:rw hello //指定user2用户组对hello文件有读写权限

setfacl -m m:r hello //指定该文件中最大生效的权限,但不稳定,会随着其他的设定而修改

setfacl -x <u|g>:<username|groupname> 文件名 //删除某一个acl权限

setfacl -x d:<u|g>:<username|groupname> 目录名Page 5 of 7

//删除某目录下新建文件默认的一个acl权限

 

-x  取消某个权限

-b  取消所有权限

   例子:

setfacl -x u:user2 hello //删除user2用户对hello文件的特殊权限

setfacl -x g:user2 hello //删除user2用户组对hello文件的特殊权限

setfacl -b 文件名 //删除该文件所有的acl权限

setfacl -b 目录名 //删除某目录下新建文件默认的所有的acl权限

   例子:

setfacl -b hello

3)getfacl

   例子:

[root@server136 ~]# getfacl hello

# file: hello //文件名

# owner: root //文件所有人

# group: root //文件所属组

user::rw- //文件所有人对该文件的权限

user:user1:rw- //特定用户user1对该文件的权限

user:user2:rw-

group::r-- //文件所属组成员对该文件的权限

group:user2:rw- //特定用户组user2对该文件的权限

mask::rw- //默认给最大的权限

other::r-- //其他人对该文件的权限

 注意:

- umask ---   022 777-022=755 644      系统默认要去掉的权限

- mask  ---   系统默认最多要给的权限 (不稳定,跟随u,g改变)

- rhel6版本及以前的版本不支持acl功能

 

9.find命令

 

find 目录 寻找的条件 条件内容

     find /home -name “.*”     找出隐藏文件

     find /etc -name *[[:digit:]]*

 

     find /mnt/ -size  -1M //小于1M的

     find /mnt/ -tape f  普通文件

       d  目录

                       l  链接

     find /mnt/ -mmin -5   //5分钟内被修改的文件

     find /mnt/ -mindepth 3 -type d

                     深度大于3     目录类型

 

 

寻找的条件:

-name //根据名字查找

-user

-group

-perm //根据权限寻找(-666,并且;/666,或者)  |7000任意权限

-type //man find(搜寻-type)

-mmin //最后修改时间(-4,4min以内修改的)

-size //根据文件大小

-maxdepth

-mindepth

条件的连接:

-o //或者

-a //并且

对找到的所有执行:

-exec

eg: find /etc -name passwd -exec cp {} /mnt \;

 

10.locate 查找文件

 

--速度更快,但新建文件必须更新后才能找到

--更新方式:updatedb

 

11.打包

 

 tar cvf etc.tar /etc

  c: create

    v:显示过程

    f:指定包名

 

 tar tf etc.tar

   t:显示包的内容

 

 tar f etc.tar -r westosfile

-r:向包中添加文件

 

 tar f /root/etc.tar --get westosfile

--get:获取包中的westosfile文件

 

 tar f /root/etc.tar --delete westosfile

  --delete:删除包中的westosfile文件

 

 tar xf etc.tar -C /mnt/

 x:解开包

-C:指定解包的目录

 

12.压缩

1)gz格式压缩:

tar cvf etc.tar /etc/ //对/etc目录打包,并指定名称为etc.tar

du -sh etc.tar //查看etc.tar包的大小

gzip etc.tar //对etc.tar进行gz格式压缩

du -sh etc.tar.gz //查看压缩后etc.tar.gz的大小

gunzip etc.tar.gz

 

tar zcf etc.tar.gz /etc

tar zxf etc.tar.gz

2)bz2格式压缩:

bzip2 etc.tar

bunzip2 etc.tar.bz2

 

tar jcf etc.tar.bz2 /etc/

tar jxf etc.tar.bz2

3)xz格式压缩:

xz etc.tar

unxz etc.tar.xz

 

tar Jcf etc.tar.xz /etc/

tar Jxf etc.tar.xz -C /mnt

4)zip格式压缩:

zip -r etc.tar.zip etc.tar

unzip etc.tar.zip

 

bs 每一块截取多少

count  截取多少块

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值