Linux中sudoers使用記錄__Linux

來源:互聯網
上載者:User

Linux下的sudo許可權可以通過/etc/sudoers這個檔案來配置,
不過這個檔案是唯讀, 普通使用者無法修改。
有個visudo的命令, 專門來改/etc/sudoers的。

下面是一次配置實驗, 記錄下來。

實驗環境:

Distributor ID: CentOSDescription:    CentOS Linux release 7.4.1708 (Core) Release:    7.4.1708Codename:   Core

需求如下: 為新使用者配置sudo許可權, 避免其功能太弱。

開啟/etc/sudoers這個檔案, 在最後可以看到

## Read drop-in files from /etc/sudoers.d (the # here does not mean a comment)#includedir /etc/sudoers.d

意思是, 在/etc/sudoers.d中放置的檔案可以被讀取到, 文法和/etc/sudoers一致。

那麼我建立一個檔案: /etc/sudoers.d/mySudoers,
寫入如下內容(注意: 僅為樣本, 不可作為真實伺服器配置):

jz ALL=/usr/bin/*, /usr/sbin/*, /sbin/*, !/usr/sbin/fdisk, !/usr/bin/passwd, !/usr/sbin/userdel

上面的意思是說, 允許使用者jz在所有被管理的機器上(All, 目前我的就一台),
可以執行的命令為:/usr/bin/*, /usr/sbin/*, /sbin/*(*代表所有),
不可以執行的命令為:
!/usr/sbin/fdisk, !/usr/bin/passwd, !/usr/sbin/userdel。

然後退出儲存, 再將mySudoers的僅限改為440。

可能出現的問題:

sudo: /etc/sudoers.d/mySudoers is world writable
原因:mySudoers許可權不是唯讀。

Sorry, user user1 may not run sudo on gl.
原因: user1沒有配置sudo許可權 user1 is not in the sudoers file. This incident will be reported
原因: user1沒有配置sudo許可權

再次說明, 此為實驗, 不可用於真實環境。

歡迎補充指正。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.