1. 程式人生 > >Linux使用者管理與許可權

Linux使用者管理與許可權

使用者管理與許可權

實驗目的:

掌握使用者與組管理

掌握高階許可權的使用

掌握訪問控制列表

實驗步驟:

步驟一、使用者管理

建立使用者useradd的幾個引數:

-c描述

-d 家目錄

-u uid號

-g  私有組

-G  把這個使用者附加到其它組中去

-s shell環境變數  /bin/bash  /sbin/nologin它無法登陸到本地,遠端使用者可以

建立一個使用者user2,我們怎麼樣知道我們建立了user 2了呢?Id一下使用者

[[email protected] ~]# useradd  user2

[[email protected] ~]# id  user2

uid=1001(user2)  gid=1001(user2)  組=1001(user2)

我們也可以檢視使用者的配置檔案/etc/passwd,裡面記載這所有使用者的資訊

[[email protected] ~]#vim /etc/passwd

在/etc/passwd下,有三種使用者:

第一種:超級管理員root,uid為0

第二種:系統服務使用者,uid為1~999

第三種:(紅帽7)普通(本地)使用者,uid為1000往後

我們的紅帽6系統服務使用者uid是1-499.

Usermod 修改服務使用者

Userdel –r 刪除服務使用者

-r引數:

建立一個使用者或組大概會在這六個地方建立資訊

/etc/passwd /etc/shadow  /etc/group  /etc/gshadow

/home    /var/spool/mail

不新增-r引數刪除,會刪除這些/etc/passwd  /etc/shadow  /etc/group /etc/gshadow配置資訊,但不刪除/home     /var/spool/mail這兩個配置資訊

新增-r引數刪除會刪除所有的配置資訊

步驟二、組管理

建立一個dongshihui組,對這個組設定一個密碼

[[email protected] ~]#groupadd   dongshihui

[[email protected] ~]#gpasswd   dongshihui

正在修改 dongshihui 組的密碼

密碼:

切換到普通使用者user1上,把user1加入到dongshihui組中

[[email protected] ~]#   su -  user1

ABRT has detected 1 problem(s). For moreinfo run: abrt-cli list

[[email protected] ~]$ newgrp   dongshihui

密碼:

[[email protected] ~]$ id

uid=1000(user1) gid=1002(dongshihui) 組=1000(user1),1002(dongshihui)環境=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023

[[email protected] ~]$

Groupdel  -r刪除組

步驟三、高階許可權

SUID許可權:

SUID許可權僅僅只對可執行檔案(命令檔案)有效,對普通檔案無意義,只出現在第三位,如果一個可執行檔案有SUID許可權,那麼其它使用者在執行這個可執行檔案過程時會臨時擁有這個可執行檔案的所有者許可權

[[email protected] mnt]# ll /bin/ls

-rwxr-xr-x. 1 root root 117616 1月  25 2014 /bin/ls

[[email protected] mnt]# ls  -ld /root

dr-xr-x---. 14 root root 4096 5月   4 16:56 /root

[[email protected] mnt]# su  - user1

上一次登入:一 5月  4 17:15:44 CST 2015pts/0 上

[[email protected] ~]$ ls  /root

ls: 無法開啟目錄/root: 許可權不夠

[[email protected] ~]$ touch  /root/user1

touch: 無法建立"/root/user1":許可權不夠

[[email protected] ~]$ exit

登出

[[email protected] mnt]# chmod  u+s /bin/ls

[[email protected] mnt]# chmod  u+s /bin/touch

[[email protected] mnt]# ll /bin/ls

-rwsr-xr-x. 1 root root 117616 1月  25 2014 /bin/ls

[[email protected] mnt]# ll /bin/touch

-rwsr-xr-x. 1 root root 62432 1月  25 2014 /bin/touch

[[email protected] mnt]# su  - user1

上一次登入:一 5月  4 17:19:35 CST 2015pts/1 上

[[email protected] ~]$ ls  /root

anaconda-ks.cfg  test1  公共  模板  視訊  圖片  文件  下載  音樂  桌面

[[email protected] ~]$ touch  /root/test1

[[email protected] ~]$ ll /root

總用量 4

-rw-------. 1 root root  1503 4月  27 17:37 anaconda-ks.cfg

-rw-rw-r--. 1 root user1    0 5月   4 17:21 test1

drwxr-xr-x. 2 root root     6 4月  27 09:47 公共

drwxr-xr-x. 2 root root     6 4月  27 09:47 模板

drwxr-xr-x. 2 root root     6 4月  27 09:47 視訊

drwxr-xr-x. 2 root root     6 4月  27 09:47 圖片

drwxr-xr-x. 2 root root     6 4月  27 09:47 文件

drwxr-xr-x. 2 root root     6 4月  27 09:47 下載

drwxr-xr-x. 2 root root     6 4月  27 09:47 音樂

drwxr-xr-x. 2 root root     6 4月  27 09:47 桌面

SGID許可權:

SGID許可權僅僅只對可執行檔案(命令檔案)有效,對普通檔案無意義,只出現在第6位,如果一個可執行檔案有SGID許可權,那麼其它使用者在執行這個可執行檔案過程中會臨時擁有這個可執行檔案的所屬組許可權。

[[email protected] mnt]# ll  /bin/ls

-rwxr-xr-x. 1 root root 117616 1月  25 2014 /bin/ls

[[email protected] mnt]# chmod   g+s /bin/ls

[[email protected] mnt]# ll /bin/ls

-rwxr-sr-x. 1 root root 117616 1月  25 2014 /bin/ls

[[email protected] mnt]# su  - user1

上一次登入:一 5月  4 17:20:57 CST 2015pts/1 上

[[email protected] ~]$ ls  /root

anaconda-ks.cfg  test1  公共  模板  視訊  圖片  文件  下載  音樂  桌面

sticky許可權:

t許可權僅僅只對目錄有效,對任何檔案無意義!只出現在第9位!

如果一個目錄有t許可權,那麼只有檔案所有者和root使用者才能刪除檔案,其它使用者無法執行刪除檔案的操作!

假如/tmp 目錄許可權是rwxrwxrwt

 root使用者可以在這個目錄下建立和刪除任何檔案!

 但是普通使用者user1只能刪除自己建立的檔案,而不能刪除user2使用者的檔案(即使user1對user2使用者的檔案的w許可權)!

 實際應用: 一般用於重要目錄設定一個t許可權.這樣可以防止誤刪除檔案.

 [[email protected] mnt]# ls  -ld /tmp

drwxrwxrwx. 18 root root 4096 5月   4 17:46 /tmp

[[email protected] mnt]# chmod   o+t /tmp

[[email protected] mnt]# ls  -ld /tmp

drwxrwxrwt. 18 root root 4096 5月   4 17:46 /tmp

[[email protected] mnt]# cd /tmp

[[email protected] tmp]# su  user1

[[email protected] tmp]$ touch  user1

[[email protected] tmp]$ su  user2

密碼:

[[email protected] tmp]$ touch  user2

[[email protected] tmp]$ ll

-rw-rw-r--. 1 user1 user1   0 5月   4 17:59 user1

-rw-rw-r--. 1 user2 user2   0 5月   4 18:00 user2

 [[email protected] tmp]$ rm -rf  user1

rm: 無法刪除"user1":不允許的操作

步驟四、檔案訪問控制列表

傳統許可權設定無法針對單個使用者來設定許可權!

FACL(File AccessControl  List)就是對傳統許可權的補充,可以實現針對單個使用者做單獨許可權設定

getfacl  file|dir    檢視這個檔案或目錄的許可權(針對單個使用者的)

setfacl -m  u|g|o|a:username|groupname:r|w|x  file|dir 設定許可權

在/tmp目錄下有個test檔案,設定user1組使用者有rwx許可權,user1使用者有rw許可權,user2使用者有r許可權,如果做了?

[[email protected] /]# cd /tmp

[[email protected] tmp]# touch  test

[[email protected] tmp]# ll

總用量 0

-rw-r--r--. 1 root root 0 5月   8 11:22 test

[[email protected] tmp]# getfacl   test

# file: test

# owner: root

# group: root

user::rw-

group::r--

other::r—

可以看到getfacl檢視的許可權就是傳統許可權,只不過換了個形式,現在我們對test檔案設定下訪問控制列表,再來檢視。

[[email protected] tmp]# setfacl  -m  g:user1:rwx  test

[[email protected] tmp]# setfacl  -m u:user1:rw  test

[[email protected] tmp]# setfacl  -m u:user2:r  test

[[email protected] tmp]# getfacl  test

# file: test

# owner: root

# group: root

user::rw-

user:user1:rw-

user:user2:r--

group::r--

group:user1:rwx

mask::rwx

other::r--

用getfacl檢視的許可權其中既有傳統許可權又有Facl許可權

注意事項:

在紅帽6系統中,後來建立的分割槽時ext4格式的,這個分割槽時不帶Facl功能的

在紅帽7系統中,分割槽只要時xfs格式的,這些分割槽都會帶Facl功能的

步驟五、許可權委派

許可權委派就是將一部分功能委派給其它人

檢視/home,發現只有student一個使用者,切換student使用者下,useradd234使用者,許可權拒絕

[[email protected] Desktop]# cd /home

[[email protected] home]# ls

student

[[email protected] home]# su  student

[[email protected] home]$ useradd  234

bash: /usr/sbin/useradd: Permission denied

修改/etc/sudoers檔案,使得student使用者有執行useradd命令的許可權

[[email protected] Desktop]# vim  /etc/sudoers

## Next comes the main part: which userscan run what software on

## which machines (the sudoers file can beshared between multiple

## systems).

## Syntax:

##

##     user    MACHINE=COMMANDS

##

## The COMMANDS section may have otheroptions added to it.

##

## Allow root to run any commands anywhere

root   ALL=(ALL)       ALL

student  ALL=(ALL)      /usr/sbin/useradd 委派給student使用者有執行useradd命令的許可權

修改了/etc/sudoers檔案,賦予student有執行useradd命令的許可權

[[email protected] home]$ useradd  234

bash: /usr/sbin/useradd: Permission denied   為什麼還是許可權拒絕?

[[email protected] home]$ sudo  useradd  234 許可權委派在執行的時候前面一定要加一個sudo命令,否則是無效的

We trust you have received the usuallecture from the local System

Administrator. It usually boils down tothese three things:

   #1) Respect the privacy of others.

   #2) Think before you type.

   #3) With great power comes great responsibility.

[sudo] password for student:           輸入student使用者的密碼

[[email protected] home]$

[[email protected] home]$ ls   

234  student  

student使用者建立使用者234成功,成功委派了使用者student有建立使用者的許可權

相關推薦

Linux使用者管理許可權

使用者管理與許可權 實驗目的: 掌握使用者與組管理 掌握高階許可權的使用 掌握訪問控制列表 實驗步驟: 步驟一、使用者管理 建立使用者useradd的幾個引數: -c描述 -d 家目錄 -u uid號 -g  私有組 -G  把這個使用者附加到其它組中去 -s shell

第十三章 Linux 賬號管理 ACL 許可權設定

Linux 的賬號與群組 Linux 是如何辨別每一個使用者的呢? 使用者識別碼 UID 和 GID 每一個檔案都具有【擁有人與擁有群組】的屬性,每個登入的使用者都至少會擁有兩個 ID ,一個是使用者 ID (User ID) 和一個群組 ID (Group ID)。 使用者

Linux 賬號管理 ACL 許可權設定

Linux 的賬號與群組 每個登入Linux的使用者至少都會取得兩個 ID ,一個是使用者 ID (User ID ,簡稱 UID),一個是群組 ID (Group ID ,簡稱 GID)。 使用者賬號 Linux 系統上面的使用者登入主機以取得 shell 的

第十四章、Linux 賬號管理 ACL 許可權配置

要如何在 Linux 的系統新增一個使用者啊?呵呵~真是太簡單了~我們登陸系統時會輸入 (1)賬號與 (2)口令, 所以建立一個可用的賬號同樣的也需要這兩個資料。那賬號可以使用 useradd 來新建使用者,口令的給予則使用 passwd 這個命令!這兩個命令下達方法如下: us

20.Linux 賬號管理 ACL 許可權設定

Linux 登入大致過程: 1. 先尋找 /etc/passwd 裡面是否有你輸入的賬號,如果沒有跳出;如果有的話將該賬號對應的UID 和 GID(在 /etc/group 中)讀出來,另外,該賬號的主資料夾與 shell 設定也一併讀出。

Linux 學習“Linux賬號管理ACL許可權設定”

每個登入的使用者會獲得至少兩個ID,一個是UID,一個是GID;linux登入步驟,先找尋在/etc/passwd中是否有你的賬號,沒有跳出,有就去/etc/group中將賬號對應的UID與GID讀出,另外將該張海的主資料夾與shell設定一併讀出,接下來核對密碼錶進入/etc/shadow;linux中ro

Linux賬號管理ACL許可權

1、登入shell (1)/etc/passwd ①/etc/passwd檔案內容介紹,其中每一行的內容如下(共7列): 使用者名稱:密碼(都是x):UID:GID:使用者資訊說明:家目錄:使用者登入shell ②UID簡介 0 系統管理員,可以但不建議修改其他使用者的UI

Linux賬號管理ACL許可權管理(複習)

Linux 系統上面的使用者如果需要登陸主機以取得 shell 的環境來工作時, 系統都做了什麼工作? 1、先找尋 /etc/passwd 裡面是否有你輸入的賬號?如果沒有則跳出,如果有的話則將該賬號對應的 UID 與 GID (在 /etc/group 中

Linux學習筆記(3)linux服務管理啟停

重啟 禁用 multi etc 刪除服務 shel ive 系統 運行級別 一、LINUX 系統服務管理 1、RHEL/OEL 6.X及之前   service命令用於對系統服務進行管理,比如啟動(start)、停止(stop)、重啟(restart)、查看狀態(statu

Linux管理許可權管理

一、linux組基本介紹 二、檔案/目錄 所有者 三、組的建立 四、檔案/目錄 所在組 五、其他組 六、改變使用者所在組 七、許可權的基本介紹 八、rwx許可權詳情 九、檔案及目錄許可權實際案例 十、修改許可權-chmod 十一、修改檔案所有者-cho

Linux之使用者許可權

須知1:/bin 與 /sbin 為Linux中兩大環境變數路徑,其中存放著可執行檔案,/sbin 中 s 意味著 super 須知2:Linux中一切皆檔案,即所有的操作都可以以對檔案的操作實現 須知3:一般檔案的操作為:增、刪、改、查,指令的實現原理也不外如是    

MySQL使用者賬戶管理許可權管理詳解

MySQL 的許可權表在資料庫啟動的時候就載入記憶體,當用戶通過身份認證後,就在記憶體中進行相應許可權的存取,這樣,此使用者就可以在資料庫中做許可權範圍內的各種操作了。 mysql 的許可權體系大致分為5個層級: 全域性層級 全域性許可權適用於一個給定伺服器中的所有資料庫。這些許可權儲存在mysql

【轉載】Linux記憶體管理相關概念

    在Linux中經常發現空閒記憶體很少,似乎所有的記憶體都被系統佔用了,表面感覺是記憶體不夠用了,其實不然。Linux記憶體管理的一個特點是無論實體記憶體有多大,Linux 都將其充分利用(The reason Linux uses so much mem

轉載 ubuntu使用者管理許可權操作例項

原文地址https://blog.csdn.net/mountzf/article/details/51733572 ubuntu使用者管理與許可權操作例項昨天在轉載此文時提到都要把檔案及目錄許可權的操作也會獨立成文來給大家介紹,今天特地學習了使用者管理和許可權操作的例程,現總結如下。這些命令基本都是我在自

Linux學習筆記(10)linux網路管理配置之一——主機名IP地址

Linux學習筆記(10)linux網路管理與配置之一——主機名與IP地址 大綱目錄 0.常用linux基礎網路命令 1.配置主機名 2.配置網絡卡資訊與IP地址 3.配置DNS客戶端 4.配置名稱解析順序 5.配置路由與預設閘道器 6.雙網絡卡繫結   1.配置主機名 1.1

Linux檔案管理許可權管理(使用者、組、檔案管理)

1、Linux上的檔案管理類命令都有哪些,其常用的使用方法及其相關示例演示 cat命令: 檔案文字檢視工具: cat /etc/fstab cat /etc/passwd cat [OPTION] [FILE]… -n:給顯示的檔案行編號 -E:顯示行結束符$ tac命令:

RePlugin 外掛管理許可權管理

外掛化能夠提高我們程式的拓展能力,提高靈活性。Android中比較有特點的一個外掛化框架是RePlugin。 RePlugin分為宿主和外掛的概念。一個APP由 1個宿主 + n個外掛組成。宿主的主要功能是管理外掛的安裝、解除安裝、更新;外掛許可權管理等等(當然也可以將管理功能

Linux使用者管理許可權管理、歸檔、壓縮以及建立連線和測試網路網路連通性

uid:使用者標識號 gid:組標識號 預設情況下,使用者uid和gid一樣 使用者的分類: 超級使用者(root):許可權特別大,uid=0,gid=0,生產環境建議不要使用 普通使用者:uid>=500,Ubuntu一般>=1000,一般許可權系統管理,

Linux系統管理服務部署

1.   Linux系統篇 2.1            Linux系統管理 通過前兩章的學習,我們已經能夠獨立安裝Linux系統,已經掌握了Linux學習的技巧,那接下來,我們將系統的來了解Linux系統各目錄、許可權及常用命令的使用。 2.1. 1       

linux程序管理排程:task_struct結構體

程序是處於執行期的程式以及它所管理的資源(如開啟的檔案、掛起的訊號、程序狀態、地址空間等等)的總稱。注意,程式並不是程序,實際上兩個或多個程序不僅有可能執行同一程式,而且還有可能共享地址空間等資源。 Linux核心通過一個被稱為程序描述符的task_struct結構體來管理程序,這個結構體包含了一個程