linux作業系統基礎篇(二)

來源:互聯網
上載者:User

標籤:讀寫   描述   nbsp   ls -l   帳號   保留   profile   別名   uid   

命令建立使用者:useradd

手動建立使用者:

/etc/passwd

/etc/shadow

/etc/gshadow

/home/使用者名稱/

/var/spool/mail

id user 查看user使用者個人資訊。

使用者家目錄的隱藏檔案模板  /etc/skel

ls -ld 查看目錄詳細資料

chown -R oldboy:oldboy /home/oldboy 遞迴更改

 

 

家目錄下環境設定檔
env 查詢環境變數
set 查詢所有變數
環境變數可以被子進程繼承 export b=2
自訂變數不能被子進程繼承 a=1

環境設定檔(每個使用者家目錄下都存在)
.bash_history 儲存使用者的曆史命令,當使用者退出時儲存到檔案
.bash_logout 儲存使用者退出時執行的命令
.bashrc儲存使用者別名 (開啟新的終端就可以讀取該檔案)
.bash_profile 儲存使用者搜尋命令的位置

.bashrc shell層級環境變數設定檔
.bash_profile 登入層級環境變數設定檔

su - 登入層級切換
su shell層級切換

全域環境設定檔
/etc/bashrc
/etc/profile

載入順序
/etc/profile
.bash_profile
.bashrc
/etc/bashrc

定義變數檔案順序
/etc/profile1
/etc/profile2
.bash_profile1
.bashrc1
/etc/bashrc1
/etc/bashrc2
.bashrc2
.bash_profile2

許可權(基本許可權和進階許可權)
[[email protected] ~]# ls -l install.log
-rw-r--r-- 1 robin upup 39751 05-23 11:15 aa.txt
rwx | rwx | rwx
robin upup other
uid=0----->uid=robin----->group=upup----->other

對於檔案r--------cat head tail....
w--------vim,gedit,vi,> >>
x--------執行./ 絕對路徑
對於目錄r--------ls r-x查看目錄下檔案資訊
w--------mkdir touhc rm rwx
x--------cd 
user u
group g
other o

chmod u+r file/dir
chmod u+r,g+w file/dir
chmod ug-rw file/dir
chmod ugo+rwx file/dir
chmod a+rwx file/dir

chmod u=r file/dir
chmod u=r,g=w file/dir
chmod uo=rw file/dir
chmod ugo=rwx file/dir
chmod a=rwx file/dir

/rwxr-xr-x 755
/etc/rwxr-xr-x 755
/usr/rwxr-xr-x 755
/var/rwxr-xr-x 755
/tmprwxrwxrwt 1777
/etc/shadowr-------- 400
/etc/passwdrw-r--r-- 644
/home/robinrwx------ 700
/rootrwxr-x--- 750 
root建立檔案預設許可權rw-r--r-- 644
root建立目錄預設許可權rwxr-xr-x 755
普通使用者建立檔案預設許可權rw-rw-r-- 664
普通使用者建立目錄預設許可權rwxrwxr-x 775

r------4 w------2 x-----1 
777
rwxr----x 741 123--x-w--wx
r-x-wx-w- 532 456r--r-xrw-

預設許可權計算方法 
666023
110110110000010011
111101100111101100
110100100
644

chmod -R 777 /test

修改擁有者所屬組
chown robin tt.txt
chgrp uplooking tt.txt 
chown robin.uplooking tt.txt
chown .uplooking tt.txt
.=:
chown -R robin.uplooking dir/

練習:
建立使用者tom和jerry
1.在/tmp目錄下建立檔案tt.txt
要求:
tt.txt使用權限設定為651 在改為rwxr----x
chmod 651 /tmp/tt.txt
chmod u=rwx,g=r,o=x /tmp/tt.txt

設定tt.txt檔案擁有這tom所屬組jerry
chown tom.jerry /tmp/tt.txt

2.根據以下要求設定擁有者和許可權
在/tmp目錄下建立目錄test/,在test目錄下建立檔案aa.txt
tom可以讀寫檔案aa.txt 不能刪除
jerry 不可以讀寫檔案aa.txt 可以刪除

mkdir /tmp/test/
touch /tmp/test/aa.txt

/tmp/test/jerry root rwxr-xr-x
/tmp/test/aa.txt tom root rw-r-----

 

主組附加組
robin robin robin,uplooking
/tmp/test rwxrwx--- root uplooking
robin能不能進去/tmp/test? 為什麼?
可以 因為附加組有uplooking
進入後建立檔案aa.txt 該檔案 擁有者 所屬組??
robin robin
如果該使用者想建立屬於uplooking組的檔案 怎麼做?
sg uplooking
robin uplooking robin,uplooking
tt.txt robin uplooking

進階許可權
1.suid
必須作用於二進位可執行檔 
chmod u+s file
作用:任何使用者在執行擁有suid許可權的命令時,都以該命令擁有者的身份執行

實驗:
在不改變/etc/shadow許可權的前提下,使普通使用者robin可以使用cat查看/etc/shadow檔案內容
which cat
chmod u+s /bin/cat
robin使用者測試

2.sgid
必須作用於目錄
chmod g+s dir
作用:任何使用者在擁有sgid的目錄下建立的檔案,都要繼承該目錄的組

 

useradd -g job -G uplooking tom
useradd -g job -G uplooking jerry
useradd -g sal -G uplooking zorro
useradd -g sal -G uplooking shrek

/job zhb uplooking rwxrwsr-x

aa.txt tom job
tt.txt tom uplooking rw-r-----


3.sticky(t 冒險位 粘貼位)
必須作用於目錄
chmod o+t dir
作用:任何使用者在擁有t許可權的目錄下建立的檔案,都屬於該使用者自己,其他人無權刪除(root,目錄擁有者)

 

robin:$1$Bj0Exbfx$e24mczi0jmsiDR:15847:2:10:3:2::

第一列:使用者名稱
第二列:密碼(md5)
第三列:密碼最後一次修改時間(天)
第四列:密碼最小時間
第五列:密碼最大時間(密碼有效期間)(天)
第六列:密碼到期前警告時間
第七列:密碼到期後帳號到期時間
第八列:帳號有效期間
第九列:保留列

練習:
1.添加組kkk gid為1500
groupadd -g 1500 kkk
2.添加使用者 zorro uid 1500 屬於kkk組 描述:hello 家目錄/mnt shell:bash

useradd -u 1500 -g kkk -c hello -d /mnt/zorro -s /bin/bash zorro

3.通過管理員設定該使用者密碼為123
終端登入zorro 設定自己密碼為123.com


修改使用者資訊
usermod 
usermod -u -g -c -d -s robin

usermod -l abc2abc abc2
usermod -L robin
usermod -U robin
usermod -f 密碼到期後帳號到期時間
usermod -e 帳號有效期間

修改組資訊
groupmod -g 2500 uplooking
groupmod -n upup uplooking

修改密碼及資訊
passwd -n(最小時間) -x 最大時間 -w 警告時間 -i 密碼到期後帳號到期時間

passwd -l robin 鎖定密碼
passwd -u robin 解鎖密碼
passwd -S robin  查看密碼狀態

添加使用者tom和jerry 分別設定兩個使用者密碼為123
鎖定tom帳號 鎖定jerry密碼
終端登入測試 傳回值是否一致?
查看shedow檔案 兩個使用者有什麼區別?
!鎖定帳號
!! 鎖定密碼

刪除使用者:
userdel -r abc2 
刪除群組
groupdel upup


附加組
groupadd yw
groupadd kf
useradd -G kf,yw wg 覆蓋附加組資訊
useradd -a -G kf,yw wg 追加附加組資訊

groupadd boss
gpasswd boss

手動添加帳號
#####1.groupadd zu
1).vim /etc/group
zu:x:2000:

######2.useradd -g zu zhb
1).vim /etc/passwd
zhb:x:2000:2000::/home/zhb:/bin/bash
2).mkdir /home/zhb
3).cp /etc/skel/.bash* /home/zhb/

#####3.passwd zhb
1).vim /etc/shadow
zhb::15848:0:99999:7:::
2).grub-md5-crypt產生密碼 將密碼複製到第二列

終端登入測試 建立檔案?


多使用者匯入
1.匯入檔案(user.txt)內的使用者和系統的passwd檔案使用者資訊不能衝突
2.匯入檔案(user.txt)內使用者不能衝突

[[email protected] ~]# cat user.txt 
user1:x:3000:3000:ptuser:/home/user1:/bin/bash
user2:x:3001:3001:ptuser:/home/user2:/bin/bash

newusers < user.txt

[[email protected] ~]# cat passwd.txt
user1:123
user2:123

chpasswd < passwd.txt

linux作業系統基礎篇(二)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.