且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

菜鸟学Linux 第021篇笔记 特殊权限SUID、FACL、Linux 终端

更新时间:2022-01-18 16:24:27


菜鸟学Linux 第021篇笔记  特殊权限SUID、FACL、Linux 终端




xargs  


特殊权限


SUID:运行某程序时,相应进程的属主是程序文件自身的属主,而不是启动者所属主

chmod u+s FILE

chmod u-s FILE

如果FILE本身此前就有执行权限,则SUID显示为s;否则显示S大写;

应用场景:passwd

SGID:运行某程序时,相应进程的属组是程序文件自身的属组,而不是启动者所属的基本组

chmod G+s FILE

chmod G-s FILE

应用场景:可以给一个目录组加S ,则其它用户在该目录建立文件时,

都属于该文件夹的基本组

bug: 可以删除其它用户建立的文件(stick可以补这个问题)

 

stick:在一个公共目录,每个用户都可创建和删除自己文件,但不可以删除其它用户

chmod o+t DIR

001stick

010 SGID

100 SUID


chmod 1755 /back/test

chmod 3755 /back/test

chmod 7755 /back/test


umask 0022


文件系统访问列表

FACL: File system Access Control List

利用文件扩展保存额外的访问控制权限


setfacl(set file access control lists)

-m设定d:可以设置目录

u:Uname:perm

g:Gname:perm

-x取消

u:Uname

g:Gname

e.g.setfacl -m d:u:user1:rx

setfacl -m g:Gname:w

setfacl -x u:user

getfacl(get file access control lists)



安全上下文件查询顺序

Owner --> Group -->  Other

Owner --> facl,user --> Group --> facl,group --> Other





Linux 终端


command

w(Show who is logged on and what they are doing.)

who(show who is logged on)

-r(print current runlevel)

whoami(print effective userid)

last(show listing of last logged in users)

-n(num The same.)

显示/var/log/wtmp 文件

  

lastb显示登录未成功的连接

显示/var/log/btmp 文件

lastlog(reports the most recent login of all users or of a given user)

-uPrint the lastlog record for user with specified LOGIN only.

basename (strip directory and suffix from filenames)

$0 这样就可以取第0段字符最后一段文本

例如/root/adminusers.sh

如在脚本里写basename $0   则可以取出adminusers.sh名字  即基名

mail(send and receive mail)

-sSpecify subject on command line

hostname(show or set the system’s host name)


终端类型:

console:控制台

PTY 物理终端(VGA)

tty 虚拟控制台(VGA)

ttyS:串行终端

pts/#伪终端

特殊变量

$0取脚本执行名称

RANDOM 0-32768



随机数生成器: 熵池

RANDOM 0-32768

/dev/random

/dev/urandom




脚本练习

1、利用RANDOM 生成10个随机数,并找出其中的最大值和最小值;





Key

1.#!/bin/bash 

declare -i MAX=0

declare -i MINI=32769

for I in `seq 10`; do

RANGE=$RANDOM

 echo -n $RANGE,

 if [ $RANGE -gt $MAX ]; then

MAX=$RANGE

 fi

 if [ $RANGE -lt $MINI ]; then

MINI=$RANGE

 fi

done

echo -e "\n Max $MAX  MINI: $MINI"

本文转自Winthcloud博客51CTO博客,原文链接http://blog.51cto.com/winthcloud/1866291如需转载请自行联系原作者


Winthcloud