1. 程式人生 > >Linux中sudo的用法

Linux中sudo的用法

ber code als 安裝 有效 ould using span 帶來

在linux中的用戶只有2種:root和非root。而非root即普通用戶的權限非常低,基本處理自己的home目錄,其他好多地方連查看的權利也沒有,更不要說安裝軟件了。

為了避免來回切換root,linux加入了sudo命令,即:可以臨時切換的root來執行一些系統命令,用完之後,在返回普通用戶,這樣既避免長期使用root帶來的安全風險,

又有效的減少了切換root的頻率。

1、sudo命令的配置主配置文件:/etc/sudoers,不過,系統文檔推薦的做法,不是直接修改/etc/sudoers文件,而是將修改寫在/etc/sudoers.d/目錄下的文件中。

任何在/etc/sudoers.d/目錄下,不以~號結尾的文件和不包含.

號的文件,都會被解析成/etc/sudoers的內容。另外要註意:如果使用這種方式修改sudoers,

需要在/etc/sudoers文件的最後行,加上#includedir /etc/sudoers.d語句(默認已有)。

註意了,這裏的指令#includedir是一個整體, 前面的#號不能丟,也不能在#號後有空格。並且,盡可能使用visudo來編輯sudoers, 因為有相關的錯誤識別機制。

相關文檔:

# This will cause sudo to read and parse any files in the /etc/sudoers.d
# directory that do not end in ‘~‘ or contain a ‘.‘ character.

# Note that there must be at least one file in the sudoers.d directory (this
# one will do), and all files in this directory should be mode 0440.

# Note also, that because sudoers contents can vary widely, no attempt is
# made to add this directive to existing sudoers files on upgrade.

# Finally, please note that using the visudo command is the recommended way
# to update sudoers content, since it protects against many failure modes.

2、具體的配置命令

Linux中sudo的用法