1. 程式人生 > >linux簡單授權

linux簡單授權

linux授權:
r: read
w: write
x:execute
ch:change


b=byte
1byte=8 bits
u=user owner
g=group
o=other
a=all
_ _ _ _ _ _ _ _ _
r w x r w x r w x
u g o a
所有者授權

0 0 1 --->1 不可讀,不可寫,要執行
0 1 0 --->2 不可讀 可寫,不可執行
0 1 1 --->3 不可讀 可寫,可執行
1 0 0 --->4 可讀,不可寫,不可執行
1 0 1 --->5 可讀,不可寫,可執行
1 1 0 --->6 可讀,可寫,不可執行
1 1 1 --->7 可讀,可寫,可執行


【r=4、w=2、x=1】
檔案擁有者僅有隻讀許可權,而檔案所屬組使用者具有讀、寫許可權,其他使用者具備讀、寫、執行三種許可權可以寫成下列命令:
chmod 467 test 【w=4、r=2、x=1】

 

[[email protected] tmp]# ls -al | grep test.txt
-rw-r--r-- 1 root root 20 06-19 01:50 test.txt

chmod u+x test.txt
chmod g+w test.txt
chmod o+x test.txt
chmod a+x test.txt
[[email protected]

python]# chmod u+x,g+x,o+x hw.py


[[email protected] python]# cat hw.py
#!/usr/bin/python
print "hello world,this is my first python program"

[[email protected] python]# chmod u+x,g+x,o+x hw.py

[[email protected] python]# chmod a+x hw.py

[[email protected] python]# ./hw.py
hello world,this is my first python program


grp=group
chgrp=change group


own=owner
chown=change owner


練習:
使用root賬戶登入系統,在test10使用者的家目錄內新建一檔案1.log
檔案內容’hello, my name is hanmeimei’
更改檔案的許可權為640
任意新建一個組group10,組id6001
使1.log屬於這個組group10(chgrp)
通過更改使用者所屬組的方法使得1.log能夠被普通使用者test10所訪問


[[email protected] ~]# useradd test10
[[email protected] ~]# cat /etc/passwd | grep test10
test10:x:10008:10008::/home/test10:/bin/bash
[[email protected] ~]#
[[email protected] ~]# passwd test10
Changing password for user test10.
New UNIX password:
BAD PASSWORD: it does not contain enough DIFFERENT characters
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
[[email protected] ~]#
[[email protected] ~]# cd /home/test10
[[email protected] test10]#
[[email protected] test10]# pwd
/home/test10
[[email protected] test10]#
[[email protected] test10]# vi 1.log

hello,my name is hanmeimei
~
"1.log" [New] 1L, 27C written
[[email protected] test10]#
[[email protected] test10]# ls -al | grep 1.log
-rw-r--r-- 1 root root 27 06-19 05:19 1.log
[[email protected] test10]# cat 1.log
hello,my name is hanmeimei
[[email protected] test10]#
[[email protected] test10]# chmod 640 1.log
[[email protected] test10]#
[[email protected] test10]# ls -al | grep 1.log
-rw-r----- 1 root root 27 06-19 05:19 1.log
[[email protected] test10]#
[[email protected] test10]# groupadd -g 6001 group10
[[email protected] test10]#
[[email protected] test10]# cat /etc/group | grep group10
group10:x:6001:
[[email protected] test10]#whoami
root

下面是使用test10登入:
[[email protected] ~]$ whoami
test10
[[email protected] ~]$ cd /home/test10
[[email protected] ~]$
[[email protected] ~]$ ls -al | grep 1.log
-rw-r----- 1 root root 27 06-19 05:19 1.log
[[email protected] ~]$
[[email protected] ~]$ cat 1.log
cat: 1.log: 許可權不夠
[[email protected] ~]$
[[email protected] ~]$ whoami
test10


下面切回來,再使用root使用者操作:
[[email protected] test10]#whoami
root
[[email protected] test10]# chgrp group10 1.log
[[email protected] test10]#
[[email protected] test10]# ls -al | grep 1.log
-rw-r----- 1 root group10 27 06-19 05:19 1.log
[[email protected] test10]#
[[email protected] test10]# usermod -g group10 test10
[[email protected] test10]#
[[email protected] test10]# cat /etc/passwd | grep test10
test10:x:10008:6001::/home/test10:/bin/bash
[[email protected] test10]#
[[email protected] test10]#


下面是使用test10登入:
[[email protected] ~]$ whoami
test10
[[email protected] ~]$ cd /home/test10
[[email protected] ~]$
[[email protected] ~]$ ls -al | grep 1.log
-rw-r----- 1 root group10 27 06-19 05:19 1.log
[[email protected] ~]$ cat 1.log ---->現在可以檢視到1.log的內容了。
hello,my name is hanmeimei
[[email protected] ~]$
[[email protected] ~]$

檔案型別
c--character 字元裝置檔案
b--block 塊裝置檔案
兩個裝置檔案的區別:
主要的區別是兩個裝置檔案訪問應用程式順序不一樣,是否可以隨機訪問
字元裝置檔案是按順序來讀取或是儲存應用程式,按位元組讀取資料
塊裝置檔案是隨機讀取或是儲存應用程式,按塊讀取資料,1塊=512B

/dev
dev=device

l 符號連結檔案
l=link


[[email protected] tmp]# touch aaa
[[email protected] tmp]# ln aaa bbb
[[email protected] tmp]# ls -al | grep bbb
-rw-r--r-- 2 root root 0 06-19 06:21 bbb
[[email protected] tmp]#

手動修改網路地址:
[[email protected] tmp]# vi /etc/sysconfig/network-scripts/ifcfg-eth0
# Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE]
DEVICE=eth0
BOOTPROTO=static ---》static:手動配置靜態IP地址
#BROADCAST=192.168.4.255
HWADDR=00:0C:29:56:D1:87
#NETWORK=192.168.4.0
IPADDR=192.168.17.14 ---》配置IP地址
NETMASK=255.255.255.0 ---》配置子網掩碼
GATEWAY=192.168.17.1 ---》配置預設閘道器
ONBOOT=yes

重啟網路服務
[[email protected] test10]# service network restart

關閉網路服務
[[email protected] test10]# service network stop

開啟網路服務
[[email protected] test10]# service network start


[[email protected] home]# uname -a
Linux localhost.localdomain 2.6.18-164.el5 #1 SMP Tue Aug 18 15:51:54 EDT 2009 i686 i686 i386 GNU/Linux

系統名:Linux
主機名:localhost.localdomain
作業系統的發行版號:2.6.18-164.el5
核心版本號:#1 SMP Tue Aug 18 15:51:54 EDT 2009 kernel編譯時固化下來的 核心編譯次數,version檔案記載,編譯時間
機器硬體(CPU)名:i686
系統處理器的體系結構:i686
硬體平臺:i386
作業系統:Gun/Linux

 

SSH:用於遠端連線電腦 埠號:22
ssh工作:putty, secureCRT

winscp

在普通使用者登入系統,切到root使用者
su root

[[email protected] ~]$
[[email protected] ~]$
[[email protected] ~]$ su root
口令:
[[email protected] test]#
[[email protected] test]# whoami
root
[[email protected] test]#