2011-2.26 陈老师UIE笔记

2011-2.26 陈老师UIE笔记

[@more@]

基本权限位
r w x
4 2 1
------------------
chmod 777 /file
rwxrwxrwx
------------------
高级权限位
普通用户可以改密码的前提是要对/etc/shadow有写权限、

1、set uid ,设置UID位,又称suid位。
chmod u+s /file 。往往给可执行文件加。
当用户执行拥有SUID权限位的文件时,计算权限时所使用的EUID,将不再是当前用户的UID,而是文件的所有者的UID。如果文件的所有者是root,那么意味着,此可执行文件接下来的文件操作对应是root权限
用数值4表示
chmod u+s /file

[root@localhost ~]# ls -l /bin/cat
-rwxr-xr-x 1 root root 23132 2010-02-23 /bin/cat

[sungy@localhost ~]$ cat /etc/shadow
cat: /etc/shadow: 权限不够

[root@localhost ~]# chmod u+s /bin/cat
[root@localhost ~]# ls -l /bin/cat
-rwsr-xr-x 1 root root 23132 2010-02-23 /bin/cat

[sungy@localhost ~]$ cat /etc/shadow
root:$1$qTSUAati$ZZUCoHgGsdBaxkdv.EFUD.:15026:0:99999:7:::
............
sungy:!!:15032:0:99999:7:::
[sungy@localhost ~]$

[root@localhost ~]# find /bin/ -perm 4755 -ls 查看可执行文件哪些有SUID权限位()
关于find命令,参考http://www.linuxsir.org/main/?q=node/137#1.1

2、set gid ,设置gid位,sgid位。
chmod g+s /file .往往给目录加。
当用户在此目录下创建文件时,文件的所有者将是当前用户,而所属组将继承此目录的所属组。
----------
如以一实例:
实现同组成员上传的文件,可以相互写
[root@server ~]# useradd u1
[root@server ~]# useradd u2
[root@server ~]# useradd u3
-------
[root@server ~]# gpasswd -a u1 g1
Adding user u1 to group g1
[root@server ~]# gpasswd -a u2 g1
Adding user u2 to group g1
[root@server ~]# gpasswd -a u3 g1
Adding user u3 to group g1
-------
[root@server ~]# ls -ld /test
drwxrwxrwx 3 root root 4096 Feb 26 11:29 /test
[root@server ~]# chgrp g1 /test
[root@server ~]# ls -ld /test
drwxrwxrwx 3 root g1 4096 Feb 26 11:29 /test
[root@server ~]# chmod g+s /test
-----
[u3@server test]$ whoami
u3
[u3@server test]$ ls -ld u2_dir/
drwxrwsr-x 3 u2 g1 4096 Feb 26 11:31 u2_dir/
[u3@server test]$ ls -ld u2_file
-rw-rw-r-- 1 u2 g1 6 Feb 26 11:31 u2_file
[u3@server test]$ mkdir u2_dir/aaa
[u3@server test]$ vim u2_file

3、sticky位,一般给所有用户都能写的目录加。
chmod o+t /file
如果一个目录用户都可以w此目录,创建和删除。
如果希望用户只能删除自己所有的文件,而不能删除其它人所有的文件,则需要使用sticky位

suid 4
sgid 2
sticky 1
chmod 7777 /file rwsrwsrwt
chmod 4755 /file rwsr-xr-x

set sticky位,一般给所有用户都能些的目录加。防删除位,
[root@localhost ~]# chmod o+t test/
drwxrwsrwt 3 root g1 4096 02-27 19:44 test
在该目录下的文件中,只有文件属于自己的才能删除,其他人不能删,尽管同一组也不行
[ub@localhost test]$ rm -rf ua_file
rm: 无法删除 “ua_file”: 不允许的操作

chmod 7777 /file rwsrwsrwt
chmod 4755 /file rwsr-xr-x


[root@localhost test]# md5sum /etc/passwd
0752fe07d363a2ca5cc50370fc013f0b /etc/passwd 只要文件没有被改动,结果是一样的

[root@localhost sungy]# find ./test -type f -exec md5sum {} ; > ./111
[root@localhost sungy]# ls
111 2011-2.26.txt install.log install.log.bak red5_5.iso test
[root@localhost sungy]# cat 111
9ed914791ba218af0fb64f1758e01fa9 ./test/c.patch
d41d8cd98f00b204e9800998ecf8427e ./test/ccc
dd8c6a395b5dd36c56d23275028f526c ./test/a
dd8c6a395b5dd36c56d23275028f526c ./test/b
08ab09a3f8942b1f0c9aa55084686207 ./test/find.txt
d41d8cd98f00b204e9800998ecf8427e ./test/ddd

高级文件操作命令和正则表达式
head
tail
cat
less
more
grep

cut -d: -f1,3 /etc/passwd
-d 指定分隔符
-f 指定分割以后的第N段
cut -d: -f1-3,7 /etc/passwd

sort /etc/passwd 按首字符排序 正序
sort -r /etc/passwd 反序
sort -n /file1 按数值大小排序
sort -t: -k3 -n /etc/passwd
-t 指定分隔符
-k 指定按第N段排序
-n 表示按数值大小排序,而/etc/passwd的以:分隔的第3段就是UID
uniq /file1 把文件中连续的重复行只显示一次。
uniq -c /file1 把文件中连续的重复行只显示一次,-c 表示并显示此行重复的次数。
如:/file1内容如下,进行操作
[root@server ~]# cat /file1
1
1
1
1
11
22
22
22
22
1
1
1
11
11
33
44421
123
15

sort /file1 | uniq -c | sort -r

[root@server ~]# wc /etc/passwd
37 56 1647 /etc/passwd
[root@server ~]# wc -l /etc/passwd
37 /etc/passwd
[root@server ~]# wc -w /etc/passwd
56 /etc/passwd
[root@server ~]# wc -c /etc/passwd
1647 /etc/passwd

ftp://192.168.1.254/

[root@server ~]# find /home -type f -exec md5sum {} ; > /tmp/file2
[root@server ~]# find /home -type f -exec md5sum {} ; > /tmp/file
[root@server ~]# diff /tmp/file /tmp/file2

[root@server ~]# diff -e a b > c.diff
c.diff 是a的补丁文件,所以只能给a打补丁,使其等同于b
[root@server ~]# cat a
123123123
[root@server ~]# cat b
123123
1211111

[root@server ~]# patch a < c.diff
[root@server ~]# cat a
123123
1211111

[root@server ~]# cat b
123123
1211111

[root@server ~]#


[root@server ~]# tr 'o' 'O' < /etc/passwd
[root@server ~]# echo $PATH
/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
[root@server ~]# echo $PATH | tr ":" " "
/usr/kerberos/sbin /usr/kerberos/bin /usr/local/sbin /usr/local/bin /sbin /bin /usr/sbin /usr/bin /root/bin

tr -d f < /tmp/passwd
表示把文件中的f字符串删除,但是注意并不实际改变文件内容,而是文件的输出内容做改变。

tr命令:只能重定向,不能读取文件
[root@localhost sungy]# tr 'o' 'O' < /etc/passwd 替换,但不改变本文件本身
rOOt:x:0:0:rOOt:/rOOt:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nOlOgin

[root@localhost sungy]# echo $PATH | tr ":" " "
/usr/kerberos/sbin /usr/kerberos/bin /usr/local/sbin /usr/local/bin /sbin /bin /usr/sbin /usr/bin /usr/X11R6/bin /root/bin
[root@localhost sungy]# echo $PATH
/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin

[root@localhost sungy]# tr -d o < /etc/passwd 删除字符操作
rt:x:0:0:rt:/rt:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nlgin


合并 文件内容
[root@server ~]# paste -d "t" /tmp/file /tmp/file2
[root@server ~]# paste -d "-" /tmp/file /tmp/file2
分割文件
[root@server a]# split -b 100 file 把文件分为100字节为一个单位的文件
[root@server a]# split -l 10 file 把文件每10行分成一个文件
分完以后的文件名如下: xaa xab xac

[root@localhost sungy]# cat xa* <=> [root@localhost sungy]# cat xaa xab xac xad 合并文件

[root@server a]# cut -d : -f 3 /etc/passwd | sort -n | tr 'n' ' '
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 28 29 32 38 42 43 47 51 68 69 70 74 77 81 86 99 100 500 501 502 503 65534
----------------

[root@server ~]# grep -v root /etc/passwd
-v 表示取反,不包含root字符串的行
[root@server ~]# grep -c root /etc/passwd
-c 表示统计,统计出包含root字符串的行的行数
[root@server ~]# grep -n root /etc/passwd
-n 显示行号,表示把包含root字符串的行的行号显示出来
[root@server ~]# grep -i Root /etc/passwd
-i 不区分大小写

正则表达式 regular expression
^
^string 表示行以string开头
[root@server ~]# grep '^root' /etc/passwd
root:x:0:0:root:/root:/bin/bash

$
string$ 表示 行以string字符串结尾
[root@server ~]# grep 'sh$' /etc/passwd
root:x:0:0:root:/root:/bin/bash
pg:x:500:500::/home/pg:/bin/bash
u1:x:501:502::/home/u1:/bin/bash
u2:x:502:503::/home/u2:/bin/bash
u3:x:503:504::/home/u3:/bin/bash

[root@server ~]# grep '^123$' /file 仅仅有123字符串的行

123
[root@server ~]# grep -n '^$' /file 空行

. 表示任意的一个字符

[abcde] 表示一个字符。这个字符可能是a,b,c,d,e
[a-e]
[a-zA-Z0-9] 表示一个字符,其可以是小写字母或者大写字母或者是数字
[^A-Za-z0-9] 表示不是小写字母大写字母数字的字符

[root@server a]# grep '^[^#]' /etc/vsftpd/vsftpd.conf
[root@server a]# grep -v '^#' /etc/vsftpd/vsftpd.conf


[a-z][a-z] 表示两个小写字母

* 此符号总是和其前一个字符一起看。
a* 表示重复a任意次.也就是说 0个a,1个a,2个a,......
aa* 表示至少一个a
[a-z][a-z]* 这个则表示:小写字母组成的字符串,可以认为是单词(小写字母的)


a{5} 表示a重复5次
a{3,} 表示a重复3次及以上
a{1,3} 表示a重复3次及以下


[root@server ~]# grep 'ro{2}' /etc/passwd
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin
rooo:x:504:505::/home/rooo:/bin/bash
[root@server ~]# grep 'ro{2}' /etc/passwd
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin
rooo:x:504:505::/home/rooo:/bin/bash
[root@server ~]# grep 'ro{2}[^o]' /etc/passwd
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin

ot> 表示单词以ot结尾
以空格或者特殊符号分隔的连续的字符串(大小写字母和数字)认为是单词


[root@server a]# grep --color 'ot>' /etc/passwd
[root@server a]# grep --color '

[root@server ~]# grep '[^[:alnum:]]' /etc/passwd
[^a-zA-Z0-9]
[root@server ~]# grep '[[:alnum:]]' /etc/passwd
[^a-zA-Z0-9]
[root@server ~]# grep '[[:digit:]]' /etc/passwd
[0-9]
[root@server ~]# grep '[[:lower:][:upper:]]' /etc/passwd
[a-zA-Z]
[root@server ~]# grep '[[:upper:]]' /etc/passwd
[A-Z]

以上都是基本正则 grep 'basic regexp' file
还有扩展正则.使用时:grep -E 'extend regexp' file
egrep 'extend regexp' file
1、 基本正则中的aa* 在扩展正则中可以用 a+ 来方便的表示。表示1个及N个重复的a字符
2、 a? 表示有a或者没a
3、 (aa)+ 用括号表示一个字符模式,需要把这个模式看成一个整体
4、 a|b 表示a或者b
[root@server ~]# grep -E '^(a|b)' /etc/passwd
[root@server ~]# grep -E '^a|^b' /etc/passwd
[root@server ~]# grep -E 'bash$|^adm' /etc/passwd
5、a{5}
a{1,5}
a{5,}
(abc){1,3}
(abc){4,}
(abc){5}

[root@server ~]# egrep --color '(ro){1,3}' /etc/passwd
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin
rooo:x:504:505::/home/rooo:/bin/bash
rororo:x:505:506::/home/rororo:/bin/bash
[root@server ~]# egrep 'ro{3}' /etc/passwd
UID为3位数的用户信息
[root@server ~]# grep '^[^:]*:[^:]*:[0-9]{3}:' /etc/passwd
games:x:12:100:games:/usr/games:/sbin/nologin
avahi-autoipd:x:100:101:avahi-autoipd:/var/lib/avahi-autoipd:/sbin/nologin
pg:x:500:500::/home/pg:/bin/bash
u1:x:501:502::/home/u1:/bin/bash
u2:x:502:503::/home/u2:/bin/bash
u3:x:503:504::/home/u3:/bin/bash
rooo:x:504:505::/home/rooo:/bin/bash
rororo:x:505:506::/home/rororo:/bin/bash

/dev/null 黑洞设备文件 不占空间 ls 1> /dev/null <=> ls > /dev/null 1可以省略
ls -l / fff 1> /dev/null 将正确的信息扔掉
ls -l / fff 2> /dev/null 将错误的信息扔掉
ls -l / fff &> /dev/null 将正确的和错误的都扔掉

> /tmp/file 将file文件清空 等价于 1> /tmp/file
类似于tr命令很少见,只能通过输入重定向来读内容

430 ls 1> /tmp/file
432 ls 1> /dev/null
433 ls -l / fff
434 ls -l / fff 1> /dev/null
435 ls -l / fff 2> /dev/null
436 ls -l / fff
437 ls -l / fff 2> /dev/null
438 ls -l / fff 1> /dev/null
439 ls -l / fff &> /dev/null
440 echo fdjldfsl
441 echo fdjldfsl >> /tmp/file
442 > /tmp/file
443 1> /tmp/file
444 cat /tmp/file
445 echo fdjldfsl 1>> /tmp/file
446 echo fdjldfsl >> /tmp/file
447 cat /tmp/file
448 echo fdjldfsl 2>> /tmp/file
449 cat /tmp/file
450 echo fdjldfsl &>> /tmp/file

453 tr 'n' ' ' < /tmp/file
454 echo fdjsklfds
455 echo fdjsklfds 2> /tmp/a
456 cat /tmp/a
457 lsj fldsjlkfdsjkl
458 echo fdjsklfds 2> /tmp/a
459 lsj fldsjlkfdsjkl 2> /tmp/a
460 cat /tmp/a
461 cat -n /etc/passwd | tail -n 1
462 cat -n /etc/passwd | tail -n 1 > /tmp/a


[root@server ~]# > /tmp/a
[root@server ~]# cat -n /etc/passwd |tail -n 1 | tee /tmp/a
39 rororo:x:505:506::/home/rororo:/bin/bash
[root@server ~]# cat /tmp/a
39 rororo:x:505:506::/home/rororo:/bin/bash

[root@localhost /]# cat -n /etc/passwd | tail -n 1 1> /tmp/a
[root@localhost /]# cat /tmp/a
39 uc:x:504:505::/home/uc:/bin/bash

[root@localhost /]# cat -n /etc/passwd | tail -n 1 |tee /tmp/a tee是将管道传过来的信息在屏幕上显示一份并且存文件一份
39 uc:x:504:505::/home/uc:/bin/bash
[root@localhost /]# cat /tmp/a
39 uc:x:504:505::/home/uc:/bin/bash

[root@server ~]# cat > /tmp/a <> jlfjklsdf
> fsdjklsdfjklsdf
> sdfsjklsdfjklsdf
> EOF


<< 定义临时缓冲区的结束符
[root@localhost dev]# cat > /tmp/a <> fdfsf
> fdsfsdfadsf
> fdsafasf
> eee
> EEE

groups + 用户名 查是哪个组

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/23168012/viewspace-1046761/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/23168012/viewspace-1046761/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值