linux帳號和許可權的管理

來源:互聯網
上載者:User

標籤:linux   帳號   設定檔   target   blank   

瞭解常見的帳號設定檔

學會系統管理使用者帳號、組帳號

學會設定目錄或檔案的許可權

學會設定目錄或檔案的歸屬

  • 使用者帳號檔案/etc/passwd   :儲存使用者名稱稱、宿主目錄、登入shall等基本資料

每一行對應一個使用者的帳號記錄

(所有使用者都可以訪問passwd檔案中的內容,但只有root使用者才能更改)

650) this.width=650;" width="666" height="48" title="image" style="padding-top:0px;padding-right:0px;padding-left:0px;border-top-width:0px;border-right-width:0px;border-bottom-width:0px;background-image:none;" alt="image" src="http://s3.51cto.com/wyfs02/M01/6C/6E/wKiom1VJaq2RuCgAAABS2_2dtAk615.jpg" border="0" />

  • 使用者帳號檔案/etc/shadow   :儲存使用者的密碼、帳號有效期間等資訊

(檔案的每一行內容包含九個用冒號:分割的配置欄位)

每一行對應一個使用者的密碼記錄

650) this.width=650;" width="643" height="81" title="image" style="padding-top:0px;padding-right:0px;padding-left:0px;border-top-width:0px;border-right-width:0px;border-bottom-width:0px;background-image:none;" alt="image" src="http://s3.51cto.com/wyfs02/M02/6C/6E/wKiom1VJaq3y3SvjAACJjobheSA263.jpg" border="0" />

  • 添加使用者帳號

useradd 命令:useradd [選項] 使用者名稱

命令選項:

-u:指定使用者的UID標記號

-d:指定宿主目錄,預設為/home/使用者名稱

-e:指定帳號的失效時間

-g:指定使用者的基本組名(或UID號)

-G:指定使用者的附加組名(或GID)

-M:不能為使用者建立並初始化宿主目錄

-s:指定使用者的登陸shell

執行個體:指定使用者uid1000

650) this.width=650;" width="471" height="234" title="image" style="padding-top:0px;padding-right:0px;padding-left:0px;border-top-width:0px;border-right-width:0px;border-bottom-width:0px;background-image:none;" alt="image" src="http://s3.51cto.com/wyfs02/M01/6C/6E/wKiom1VJaq3Q1RmQAADstdkIKhg651.jpg" border="0" />

執行個體:修改已存在的使用者的有效期間

650) this.width=650;" width="469" height="152" title="image" style="padding-top:0px;padding-right:0px;padding-left:0px;border-top-width:0px;border-right-width:0px;border-bottom-width:0px;background-image:none;" alt="image" src="http://s3.51cto.com/wyfs02/M00/6C/6E/wKiom1VJaq3BvPFqAACjRtgCNLY945.jpg" border="0" />

執行個體:添加使用者vpn都指定宿主目錄/ftpusers

650) this.width=650;" width="470" height="124" title="image" style="padding-top:0px;padding-right:0px;padding-left:0px;border-top-width:0px;border-right-width:0px;border-bottom-width:0px;background-image:none;" alt="image" src="http://s3.51cto.com/wyfs02/M02/6C/6E/wKiom1VJaq3A8Y0jAABoO7nQ5pA323.jpg" border="0" />

執行個體:指定mike的基本組為mike,並加入到ftpuser組,指定宿主目錄為/ftpuser/mike,不允mike通過本地登入伺服器

前提:有宿主目錄,基本組,附加組

650) this.width=650;" width="485" height="232" title="image" style="padding-top:0px;padding-right:0px;padding-left:0px;border-top-width:0px;border-right-width:0px;border-bottom-width:0px;background-image:none;" alt="image" src="http://s3.51cto.com/wyfs02/M02/6C/6A/wKioL1VJbCDCM79SAAC6iQG3iaY334.jpg" border="0" />

  • 使用者帳號的初始設定檔

檔案來源:建立使用者帳號時,從/etc/skel目錄複寫而來

主要使用者設定檔:

~/bash_profile:使用者每次登陸時執行

~/bashrc:每次進入新的bash環境時執行

~/bash_logout:使用者每次登陸時執行

執行個體:查看~/bashrc

(也可以用vim 命令對其編輯)

650) this.width=650;" width="455" height="282" title="image" style="padding-top:0px;padding-right:0px;padding-left:0px;border-top-width:0px;border-right-width:0px;border-bottom-width:0px;background-image:none;" alt="image" src="http://s3.51cto.com/wyfs02/M00/6C/6E/wKiom1VJarCDPfqRAADHcQeSJrM720.jpg" border="0" />

  • 設定/更改使用者口令passwd [選項] 使用者名稱

-d:清空使用者密碼,使之無需密碼即可登陸

-l:鎖定使用者帳號

-S:查看使用者的狀態(是否被綁定)

-u:解鎖使用者帳號

注意:使用passwd命令不指定使用者名稱時,修改當前帳號的密碼

執行個體:設定使用者geng空密碼登陸,並查看使用者狀態

650) this.width=650;" width="397" height="142" title="image" style="padding-top:0px;padding-right:0px;padding-left:0px;border-top-width:0px;border-right-width:0px;border-bottom-width:0px;background-image:none;" alt="image" src="http://s3.51cto.com/wyfs02/M02/6C/6E/wKiom1VJarCgXamPAACPN94tWfk075.jpg" border="0" />

  • 修改使用者的帳號屬性usermod [選項]  使用者名稱

-l:更改使用者帳號的登陸名稱

-L:鎖定使用者帳號

-U:解鎖使用者帳號

-u:指定使用者的UID標記號

-d:指定宿主目錄,預設為/home/使用者名稱

-e:指定帳號的失效時間

-g:指定使用者的基本組名(或UID號)

-G:指定使用者的附加組名(或GID)

-s:指定使用者的登陸shell

執行個體:更改使用者vpn的使用者名稱為vpner

650) this.width=650;" width="422" height="126" title="image" style="padding-top:0px;padding-right:0px;padding-left:0px;border-top-width:0px;border-right-width:0px;border-bottom-width:0px;background-image:none;" alt="image" src="http://s3.51cto.com/wyfs02/M00/6C/6E/wKiom1VJarGg_0EcAACqJ99owls887.jpg" border="0" />

  • 刪除使用者帳號userdel  [選項] 使用者名稱

-r:表示連使用者的宿主目錄一併刪除

執行個體:刪除使用者mike及宿主目錄

650) this.width=650;" width="425" height="153" title="image" style="padding-top:0px;padding-right:0px;padding-left:0px;border-top-width:0px;border-right-width:0px;border-bottom-width:0px;background-image:none;" alt="image" src="http://s3.51cto.com/wyfs02/M01/6C/6E/wKiom1VJarKxzT6VAAClT-DCzcs905.jpg" border="0" />

 

  • 組帳號檔案

/etc/group:儲存組帳號的基本資料

/etc/gshadow:儲存使用者的密碼資訊

執行個體:查看使用者geng的組資訊

650) this.width=650;" width="415" height="203" title="image" style="padding-top:0px;padding-right:0px;padding-left:0px;border-top-width:0px;border-right-width:0px;border-bottom-width:0px;background-image:none;" alt="image" src="http://s3.51cto.com/wyfs02/M02/6C/6A/wKioL1VJbCOQoocJAACDF7hy4qY332.jpg" border="0" />

  • 添加組帳號groupadd [-g GID] 組帳號

執行個體:添加組和組帳號market

650) this.width=650;" width="459" height="131" title="image" style="padding-top:0px;padding-right:0px;padding-left:0px;border-top-width:0px;border-right-width:0px;border-bottom-width:0px;background-image:none;" alt="image" src="http://s3.51cto.com/wyfs02/M02/6C/6E/wKiom1VJarOyxNh8AABy1NIgJIg912.jpg" border="0" />

  • 刪除群組/添加群組成員groupwd  [選項] 組帳號名

groupwd用途:添加/刪除群組成員,設定組帳號密碼極少用

-a:向組內添加一個使用者

-d:從組內刪除一個使用者

-M:定義群組成員列表,以逗號隔開

執行個體:將使用者geng添加到xteam組中

650) this.width=650;" width="460" height="198" title="image" style="padding-top:0px;padding-right:0px;padding-left:0px;border-top-width:0px;border-right-width:0px;border-bottom-width:0px;background-image:none;" alt="image" src="http://s3.51cto.com/wyfs02/M00/6C/6A/wKioL1VJbCXCLHKeAACaSp7y6KM814.jpg" border="0" />

執行個體:將使用者geng,vpner定義到組market組中

650) this.width=650;" width="477" height="162" title="image" style="padding-top:0px;padding-right:0px;padding-left:0px;border-top-width:0px;border-right-width:0px;border-bottom-width:0px;background-image:none;" alt="image" src="http://s3.51cto.com/wyfs02/M00/6C/6A/wKioL1VJbCaDaR_AAACExOuXgN4056.jpg" border="0" />

  • 刪除群組帳號groupdel 組帳號

執行個體:刪除群組帳號xteam

注意:首先刪除使用者,在刪除群組帳號,沒有組的帳號是非常危險的

650) this.width=650;" width="456" height="211" title="image" style="padding-top:0px;padding-right:0px;padding-left:0px;border-top-width:0px;border-right-width:0px;border-bottom-width:0px;background-image:none;" alt="image" src="http://s3.51cto.com/wyfs02/M01/6C/6A/wKioL1VJbCaREJzsAACq5ygwnHo061.jpg" border="0" />

  • 查詢帳號資訊

id:查看使用者身份標識

groups:查使用者所屬的組

finger:查使用者帳號的詳細資料

執行個體:使用上述命令查看使用者vpner的資訊

650) this.width=650;" width="465" height="227" title="image" style="padding-top:0px;padding-right:0px;padding-left:0px;border-top-width:0px;border-right-width:0px;border-bottom-width:0px;background-image:none;" alt="image" src="http://s3.51cto.com/wyfs02/M02/6C/6A/wKioL1VJbCeQi7i4AAC36I8lm6c955.jpg" border="0" />

  • users、w、who命令:查詢已登陸到主機的使用者資訊

650) this.width=650;" width="499" height="225" title="image" style="padding-top:0px;padding-right:0px;padding-left:0px;border-top-width:0px;border-right-width:0px;border-bottom-width:0px;background-image:none;" alt="image" src="http://s3.51cto.com/wyfs02/M00/6C/6A/wKioL1VJbCjQ3W_0AAC219kIvWA458.jpg" border="0" />

 

  • 檔案/目錄的許可權和歸屬

存取權限:

讀取r:允許查看檔案內容,顯示目錄列表

寫入w:允許在目錄中建立,移動,刪除檔案或目錄

可執行:允許運行程式,切換目錄

650) this.width=650;" width="577" height="114" title="image" style="padding-top:0px;padding-right:0px;padding-left:0px;border-top-width:0px;border-right-width:0px;border-bottom-width:0px;background-image:none;" alt="image" src="http://s3.51cto.com/wyfs02/M01/6C/6A/wKioL1VJbCniS60gAACklr0pRxU777.jpg" border="0" />

執行個體:查看install的許可權

650) this.width=650;" width="582" height="100" title="image" style="padding-top:0px;padding-right:0px;padding-left:0px;border-top-width:0px;border-right-width:0px;border-bottom-width:0px;background-image:none;" alt="image" src="http://s3.51cto.com/wyfs02/M02/6C/6A/wKioL1VJbCmid8JAAABsMSekk-A713.jpg" border="0" />

以-開頭表示普通檔案,以d開頭表示目錄或檔案夾,以l來頭表示連結,以c開頭表示驅動

檔案預設許可權755,目錄預設644

  • 設定檔案和訪問目錄的許可權chmod

格式1:chomod [ugoa] [+,-,=] [rwx]  檔案或目錄

ugoa分別表示屬主,屬組,其他使用者,所有使用者。+,-,=分別表示增加,去除,設定許可權。

格式2:chmod nnn 檔案或目錄

nnn表示3位8進位數

常用命令選項-R:遞迴修改指定目錄下所有子選項的許可權

執行個體:給目錄install屬組增加寫的權利

650) this.width=650;" width="507" height="155" title="image" style="padding-top:0px;padding-right:0px;padding-left:0px;border-top-width:0px;border-right-width:0px;border-bottom-width:0px;background-image:none;" alt="image" src="http://s3.51cto.com/wyfs02/M02/6C/6E/wKiom1VJarjzEYRtAACeU718Hkc319.jpg" border="0" />

650) this.width=650;" width="509" height="116" title="image" style="padding-top:0px;padding-right:0px;padding-left:0px;border-top-width:0px;border-right-width:0px;border-bottom-width:0px;background-image:none;" alt="image" src="http://s3.51cto.com/wyfs02/M00/6C/6E/wKiom1VJarnjyP1gAAB7yWaIL08546.jpg" border="0" />

  • 設定檔案和目錄的歸屬chown

chown    屬主   檔案或目錄

chown: 表示屬組    檔案或目錄

chown  屬主:屬組    檔案或目錄

常用命令選項-R:遞迴修改指定目錄下所有子選項的許可權

執行個體:分別修改檔案屬主,屬組

650) this.width=650;" width="506" height="255" title="image" style="padding-top:0px;padding-right:0px;padding-left:0px;border-top-width:0px;border-right-width:0px;border-bottom-width:0px;background-image:none;" alt="image" src="http://s3.51cto.com/wyfs02/M01/6C/6E/wKiom1VJarqB1OZQAAEIMhRR-EA699.jpg" border="0" />

650) this.width=650;" width="505" height="188" title="image" style="padding-top:0px;padding-right:0px;padding-left:0px;border-top-width:0px;border-right-width:0px;border-bottom-width:0px;background-image:none;" alt="image" src="http://s3.51cto.com/wyfs02/M02/6C/6A/wKioL1VJbCygaFBwAAC1cCnC4JM271.jpg" border="0" />

執行個體:修改home檔案夾及檔案目錄的許可權為775

650) this.width=650;" width="514" height="365" title="image" style="padding-top:0px;padding-right:0px;padding-left:0px;border-top-width:0px;border-right-width:0px;border-bottom-width:0px;background-image:none;" alt="image" src="http://s3.51cto.com/wyfs02/M00/6C/6A/wKioL1VJbC6BWAxbAAGiiOGVKic875.jpg" border="0" />

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.