第九章permissions權限
multitasking systems多工系統-把cpu的時間切的小小的
multi-user systems 多使用者
● id – Display user identity
● chmod – Change a file's mode
● umask – Set the default file permissions
● su – Run a shell as another user
● sudo – Execute a command as another user
● chown – Change a file's owner
● chgrp – Change a file's group ownership
● passwd – Change a user's password
(一)擁有者/會員/群組
mate@mydebian8:~$ file /etc/shadow
/etc/shadow: regular file, no read permission
mate@mydebian8:~$ less /etc/shadow
/etc/shadow: 拒絕不符權限的操作
mate@mydebian8:~$ id
uid=1001(mate) gid=1001(mate) groups=1001(mate)
對每個檔案有讀寫執行三種模式跟權限有關
新增檔案再看檔案內容
mate@mydebian8:~$ > foo.txt
mate@mydebian8:~$ ls -l foo.txt
-rw-r--r-- 1 mate mate 0 5月 12 08:38 foo.txt
最前面的字母是檔案類型(-表示是一個regular file.
tale 9-1
l -擁有者跟群組有同樣權限
剩下九個字母是指檔案模式(指三種動作的權限擁有者
Table9-2
列出一個這個問我們這10個位元發生什麼事
chmod
Table 9-4: File Modes In Binary And Octal
Octal Binary File Mode
0 000 ---
1 001 --x
2 010 -w-
3 011 -wx
4 100 r--
5 101 r-x
6 110 rw-
7 111 rwx
所以剛剛的foo.txt以八進位來表示權限擁有者會變成644
umask還原成預設的權限
改變登入者身份
1.登出在以其他使用者身份登入
2.使用su命令(沒給參數就會直接跳到超級使用者身份
3.使用sudo命令
mate@mydebian8:~$ rm -f foo.txt
mate@mydebian8:~$ umask
0022
mate@mydebian8:~$ apt-get update
E: 無法開啟鎖定檔 /var/lib/apt/lists/lock - open (13: 拒絕不符權限的操作)
E: Unable to lock directory /var/lib/apt/lists/
E: 無法開啟鎖定檔 /var/lib/dpkg/lock - open (13: 拒絕不符權限的操作)
E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?
mate@mydebian8:~$ su
密碼:
root@mydebian8:/home/mate# apt-get update(更新所有檔案
exit跳出root身份
su -c 'command'(還沒key過
sudo讓你選擇要以哪個使用者的身份執行什麼命令
chown改變檔案的使用者/群組權限
創一個使用者tony
複製一個檔案給他
然後我想看tony的這個檔案
但我不是他沒有這個權限
所以我要用sudo去看
發現這個檔案的擁有者是root
所以我用chown去改使用者權限
chgrp也能這樣用
改變密碼
第十章processes
● ps – Report a snapshot of current processes
● top – Display tasks
● jobs – List active jobs
● bg – Place a job in the background
● fg – Place a job in the foreground
● kill – Send a signal to a process
● killall – Kill processes by name
● shutdown – Shutdown or reboot the system
kill跟killall可以砍掉造成當機的作業程序讓系統可以繼續正常運作
mate@mydebian8:~$ ps
PID TTY TIME CMD
1168 pts/0 00:00:00 ps
2266 pts/0 00:00:00 bash
pid是process的id(每次都會不一樣
tty終端
CMD(command)命令在哪裡作
table10-1process states
process是下指令的瞬間看到他們的狀況
top是可以持續顯示狀態(每隔三秒顯示一次ps
table10-3
top顯示的欄位
程式名稱-現在時間-本次的開機時間-有幾個使用者登入-
xlogo &顯示logo跟命令型態及樣式
mate@mydebian8:~$ ps
PID TTY TIME CMD
1347 pts/0 00:00:00 xlogo
1356 pts/0 00:00:00 ps
2266 pts/0 00:00:00 bash
mate@mydebian8:~$ ps
PID TTY TIME CMD
1347 pts/0 00:00:00 xlogo
1356 pts/0 00:00:00 ps
2266 pts/0 00:00:00 bash
mate@mydebian8:~$ fg %1
mate@mydebian8:~$ xlogo &
[1] 1410
mate@mydebian8:~$ bg %1
bash: bg: job has terminated
[1]+ Done xlogo
mate@mydebian8:~$ xlogo &
[1] 1447
mate@mydebian8:~$ xlogo &
[2] 1448
mate@mydebian8:~$ killall xlogo
[1]- 終止 xlogo
[2]+ 終止 xlogo
沒有留言:
張貼留言