学习笔记:云计算第四天

写在前面:周末没整理,周一啥也不会

4/16 个人笔记

如果远程登录不上 先查看ip 没有ip就重启

文件权限管理

文件权限管理:
	ll+文件名		#查看某文件的权限信息,如下
	-rw-r--r-- 1 root  root  0     4月  16 09:46 1.txt

关于-rw-r–r-- 代表权限,从后往前,每三个一分。

	-  rw-是主权限(属主)r--是属组的权限r--是其他权限
权限      属主  			 属组  			其他人

目录权限管理:

ll -d+文件名			# ll -d 查看目录权限信息

r 可读 4 (read)
w 写 2 (write)
x 执行 1 (exected)
(三个位一段)

Linux系统默认创建的文件和目录权限分别是什么

默认文件权限644
默认目录权限755

ugo文件权限对于root账号是不生效的!

更改文件权限:

chmod +权限 +文件名*

[root@txyun tmp]# chmod 750 1.txt		#修改1.txt文件的权限为750(属主权限读写执行,属组权限读执行,其他没有权限)
[root@txyun tmp]# ll 1.txt 				#查看1.txt文件的权限
-rwxr-x--- 1 root root 0 4月  16 09:46 1.txt

更改目录权限:

1. chmod +权限 +目录名

chmod -R 700 /tmp/1       #-R递归参数  修改1目录权限,该目录下所有文件权限更改为700(针对目录下有文件的,要是啥也没有,再在目录里新建文件,那这个文件的权限还是默认权限)
ll -d 目录名			#查看目录的权限,跟查看文件权限的不同在于 -d参数

2. 第二种表示权限的方式

使用ugo  :chmod g+x 2  #修改2目录所属组的权限加上执行权限	
#o+x 		#其他用户权限加上执行 
#o-x 		#其他用户权限去掉执行
#u=rx		#属主权限设置为读和执行
#a=rwx 		#代表所有人的权限都是rwx

chmod a=- 2 		#2目录所有权限修改为0,或者说关闭该目录所有权限
chmod ug=rw,o=r 2 修改ug权限都为rw,o权限为r

修改属主或属组

chown zh 1		#修改1的属主为zh
				chown .hr /opt/dir1 	#设置/opt/dir1的属主为hr组
chgrp it 1		#修改属组 

下面是一些课堂练习:

  1. 添加2个普通用户并修改密码

  2. 在/home下创建 dir1目录 并修改权限为770

     mkdir /home/dir1				#新建目录 /home/dir1
     touch /home/dir1/1.txt			#新建文件/home/dir1/1.txt
     chmod -R 770 /home/dir1		#修改dir1及其以后创建的所有的权限为770,这里使用-R递归参数
     ll -d /home/dir1				#查看dir1的权限
     ll -d /home/dir1/1.txt			#查看1.txt的权限
    
  3. 使用另外两个普通用户登录

  4. 使用root账号修改/home/dir1/1.txt 属组为hr

     chgrp hr /home/dir1/1.txt 
    
  5. 使用root账号将user1 加入到hr组

     gpasswd -a user1 hr
    
  6. 使用user1 进入目录查看;使用user2 进入查看删除,要求user1 有所有权限 user2 没有任何权限,user2 若要查看,该怎么做?把user2加入hr组,或者把o的权限放开


权限掩码:

umask 控制用户创建文件和目录的默认权限
默认的目录权限是0755,why?因为默认的umask值是0022,目录权限=0777-默认的umask值(0022)=0755
默认的文件权限是0644,why?因为。。,文件权限=0666-默认的umask值(0022) =0644

0777
root 0022(默认的umask值)=0755(默认的目录权限)
0666
0022(默认的umask值) =644(默认文件权限)
umask +0022 (修改默认文件权限为755)

umask

普通用户 0002(默认的umask值)


关于高级权限

suid(set uid)  	#给命令提权,针对二进制命令文件的,chmod u+s /usr/bin/xxx命令		#u-s取消权限
sgid(set gid)	#获得该程序所属用户组的权限,针对目录的,chmod g+s /opt/dir1
sbit(sticky bit)	#针对others来设置的 ,和上面两个一样,只是功能不同,目前只针对目录有效,对目录的作用是:当用户在该目录下建立文件或目录时,仅有自己与root才有权力删除。chmod o+t /home/dir1/

Linux系统一切皆文件

which ls 		# linux 系统原理。which ls 查询ls这个命令(路径)地址

普通用户不能进入root账户的家目录/root

给命令提权和去权:

 chmod u+s /usr/bin/某命令 		#提权
 chmod u-s /usr/bin/某命令		# 去权限

sgid 针对于目录的 suid针对命令针对文件的 针对目录的作用?当 目录添加了高级权限后,该目录下的新建文件会继承其属组。

chmod g+s /home/hr/	


mkdir /home/hr
chgrp hr /home/hr
chmod 777 /home/hr/ 
chmod g+s /home/hr/

sticky bit :others用户只能删除自己创建的文件:chmod o+t /home/ha

今日作业

  1. 创建用户jack和tom属于hr,wc组

     [root@VM-0-12-centos ~]# useradd jack -G hr,wc
     useradd:“hr”组不存在
     useradd:“wc”组不存在
     [root@VM-0-12-centos ~]# groupadd hr
     [root@VM-0-12-centos ~]# groupadd wc
     [root@VM-0-12-centos ~]# useradd jack -G hr,wc
     [root@VM-0-12-centos ~]# useradd tom -G hr,wc
    
  2. 创建用户tony,属于hr组,并且将tony的密码修改为 qianfeng 。

     [root@VM-0-12-centos ~]# useradd tony -G hr
     [root@VM-0-12-centos ~]# id tony
     [root@VM-0-12-centos ~]# passwd tony 
    
  3. 账号添加 组添加 账号删除 组删除用什么命令?

     账号添加:useradd 	删除:userdel -r
     组添加: groupadd	删除:groupdel
    
  4. 给你的同桌账号提权(同桌登陆不上的。添加账号提权即可)
    [root@VM-0-12-centos ~]# useradd tongzhuo
    [root@VM-0-12-centos ~]# passwd tongzhuo
    [root@VM-0-12-centos ~]# vi /etc/sudoers
    :110 yy G p 修改

  5. 将jack 属于hr wc 组 现在人员调动,请删除服务器相关【所有信息】 请问你都删什么?

     [root@VM-0-12-centos ~]# gpasswd -a jack hr
     [root@VM-0-12-centos ~]# gpasswd -a jack wc
     [root@VM-0-12-centos ~]# userdel -r jack
     												手动删除/etc/sudoers
    
  6. tom 现在属于wc组,现在升职了,请添加 it fd组。

    [root@VM-0-12-centos ~]# groupadd it
    [root@VM-0-12-centos ~]# gpasswd -a tom it
    [root@VM-0-12-centos ~]# groupadd fd
    [root@VM-0-12-centos ~]# gpasswd -a tom fd
    或者 usermod -G it,fd tom 再使用gpasswd -a tom wc

  7. 账号添加不上是什么原因

     曾经创建过同名账户没有删除干净?用的不是root账号?已存在同名账户?
    
     补充:
     有残留
     useradd命令被删除
     /usr/bin/
     普通用户没有权限
     磁盘空间和磁盘容量已满
    
  8. 你在企业里使用过什么操作系统?具体版本?请说出多个。

     CentOS Linux release 7.8.2003等等
    
  9. root用户的gid多少?

     0
    
  10. which命令干嘛的? 如果命令存储的文件被删除了,还可以使用么?

    查询命令存在的文件路径(地址),无法使用
    
  11. 修改普通用户xiaowang 和root的密码

    passwd xiaowang
    passwd root 或者登录后台重置密码
    
  12. 怎么判断一个账户是否存在??

    id +账户名
    
  13. 你为什么要修改SSH的默认端口??将现有端口修改为2000. 使用新端口登录

    提高服务器安全,大家都知道ssh默认端口号是22 ,那攻击者只需要知道ip和密码就可以登录,如果修改了端口,那攻击者不知道端口号也白瞎。
    
  14. /etc/ /tmp/ /home /root 分别是什么??

    /etc系统配置文件 /tmp临时存储文件( 缓存的文件(可删的))/home 普通用户的家目录 /root 是root的家目录
    
  15. 怎么查看组内成员信息??? 怎么查看用户在哪些组里?

    cat /etc/group     			
    id 用户
    

权限设置的问题:

  1. 修改 /tmp 下1的文件权限为700 使用数字

    [root@VM-0-12-centos tmp]# chmod 700 1
    
  2. 修改 /tmp下 2的目录 权限为765 使用字母

    #目录的默认权限是755,所以这里需要g=rw,o=rx
    [root@aliyun tmp]# chmod g=rw,o=rx 2
    [root@aliyun tmp]# ll -d 2
    drwxrw-r-x 2 root root 4096 5月   5 17:55 2
    
  3. 请查看 文件1 和目录2 的权限

    [root@VM-0-12-centos tmp]# ll 1
    [root@VM-0-12-centos tmp]# ll -d 2
    
  4. linux系统下 默认创建的文件及目录权限分别是多少?

     644  755   
    
  5. 使用字母给 1文件加执行权限

    [root@aliyun tmp]# chmod ugo+x 1		#题里没有标注是给哪个用户添加执行权限,这里都加上了
    [root@aliyun tmp]# ll 1			#查看文件1的权限
    -rwxr-xr-x 1 root root 0 5月   5 18:00 1
    
  6. r w x 分别代表数字是多少?

       r read 可读 4
       w write 可写 2
       x exce 可执行1
    
  7. 修改属主 , 属组命令是什么?

    chown	#修改属主的命令
    chgrp	#修改属组的命令
    
  8. 创建一个文件 /tmp/gongzi.txt 要求:此文件属于RS组,并且只有root和组成员能够读写执行。

    [root@VM-0-12-centos tmp]# groupadd RS
    [root@VM-0-12-centos tmp]# chown .RS gongzi.txt		#加.相当于更改属组,或者使用chgrp RS /tmp/gongzi.txt
    [root@VM-0-12-centos tmp]# chmod 770 gongzi.txt 
    
  9. 创建一个文件 /tmp/shebei.txt 要求只有IT组的成员和root能够读写执行,其他人有只读权限

    [root@VM-0-12-centos tmp]# groupadd IT
    [root@VM-0-12-centos tmp]# chown .IT shebei.txt
    [root@VM-0-12-centos tmp]# chmod 774 shebei.txt 
    
  10. 修改/tmp/shebei.txt权限为750 先使用chmod 777 shebei.txt 然后用字母去减 变成750

    [root@VM-0-12-centos tmp]# chmod 777 shebei.txt
    [root@VM-0-12-centos tmp]# chmod g-w,o-rwx shebei.txt	 #或者o=-
    [root@VM-0-12-centos tmp]# ll shebei.txt 
    -rwxr-x--- 1 root IT 0 4月  16 17:44 shebei.txt
    
  11. 修改/tmp/gongzi.txt权限为700 使用英文字母 表示

    [root@VM-0-12-centos tmp]# ll gongzi.txt 
    -rwxrwx--- 1 root RS 0 4月  16 17:39 gongzi.txt
    [root@VM-0-12-centos tmp]# chmod g-rwx gongzi.txt 
    [root@VM-0-12-centos tmp]# ll gongzi.txt 
    -rwx------ 1 root RS 0 4月  16 17:39 gongzi.txt
    
  12. 添加zhangsan用户指定其家目录为 /zhangsan

    useradd zhangsan -d /zhangsan
    
  13. root用户的UID 是多少?0

  14. root用户的gid多少?
    0

  15. 针对hr部门的访问目录/home/it设置权限,要求如下:

    1. root用户和hr组的员工可以读、写  其他用户无权限
    chgrp hr /home/it		#把/home/it 添加到hr组
    760
    chmod 760 /home/it/
    ll -d /home/it/
    
  16. 给/root/dir1/1.txt 添加高级权限,要求普通用户zhangsan能删除 1.txt

    mkdir /root/dir1
    touch /root/dir1/1.txt
    chmod u+s /usr/bin/rm1
    
  17. 添加高级权限,要求 xiaoli zhangsan 在 /home/dir1 只能删除自己创建的文件

    chmod o+t /home/dir1
    
  18. 要求 继承目录的权限 /home/dir2 为HR组 后续创建的所有文件的属组都是HR

     chmod g+u /home/dir2/
     touch /home/dir2/hr.txt
    [root@VM-0-12-centos ~]# ll /home/dir2/hr.txt 
    -rw-r--r-- 1 root HR 0 4月  16 20:30 /home/dir2/hr.txt
    
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值