天天看點

sudo和su指令簡介

摘要:

        sudo和su兩個指令是Linux比較常用的兩個指令,筆者最初的認知裡認為兩個指令存在某種關聯,後來發現兩個指令隻是内容上相似,本質上是兩個不相關的指令。sudo指令用來在普通使用者中擷取系統管理者權限執行特定任務,提高系統安全性。su指令用來轉換已登入會話的owner,說簡單一點就是轉換使用者。

sudo指令

sudo (/ˈsuːduː/or/ˈsuːdoʊ/, superuser do) is a utilityfor UNIX- and Linux-based systems that provides an efficient way to givespecific users permission to use specific system commands at the root (mostpowerful) level of the system. Sudo also logs all commands and arguments.

超級使用者執行(superuser do,sudo)是一個Unix系統工具,它提供一個有效方法,允許給定使用者在系統的root(權利最大)層次使用特定的系統指令。sudo還記錄所有的指令和參數。它允許系統管理者配置設定給普通使用者一些合理的“權利”,讓他們執行一些隻有超級使用者或其他特許使用者才能完成的任務,進而減少root使用者的登陸次數和管理時間,提高系統安全性。

使用sudo,能夠實作如下操作:

(1)讓有些使用者(或者使用者群)能夠在系統操作的root層次運作一些(或所有)指令。

(2)控制使用者能在各個主機使用的指令。

(3)從記錄清楚的檢查哪些使用者使用了哪些指令。

(4)使用時标檔案,控制使用者輸入密碼以及獲得适當權益之後必須輸入指令的時間長短。

配置sudo。配置sudo必須通過編輯/etc/sudoers檔案,而且隻有超級使用者才可以修改它,還必須使用visudo編輯。之是以使用visudo有兩個原因,一是它能夠防止兩個使用者同時修改它;二是它也能進行有限的文法檢查。是以,即使隻有一個超級使用者,也最好用visudo來檢查一下文法。

su指令

The su (substitute user) command makes it possible to change a login session's owner(i.e., the user who originally created that session by logging on to thesystem) without the owner having to first log out of that session.

Although su canbe used to change the ownership of a session to any user, it is most commonlyemployed to change the ownership from an ordinary user to the root (i.e.,administrative) user, thereby providing access to all parts of and all commandson the computer or system. For this reason, it is often referred to (although somewhatinaccurately) as the superuser command. It is also sometimes called the switch user command.

su is usuallythe simplest and most convenient way to change the ownership of a login sessionto root or to any other user.

Moreimportantly, it provides a safer way for administrators on multi-user systems(as well as for users on home computers or other single-user systems) to usethe system than to routinely log on as the root user. That is, there is muchless potential for accidental or malicious damage if an administrator firstlogs on as an ordinary user (who, by default, has very limited systemprivileges) and uses that account for routine tasks that do not require root'ssweeping powers. su can then be used to switch to the root account for onlythose operations that actually require root access (e.g., making system repairsand managing user accounts).

su(switch user的縮寫,有的地方也被看作是substituteuser的縮寫)用于以其他使用者的身份來打開一個shell或者登入界面。當該指令不加任何參數運作時,su指令将假設你想成為root。當運作該指令時,你将被提示輸入密碼。輸入的密碼即你想切換到的使用者的密碼。例如,如果想成為root,在終端中運作su,則将需要輸入root使用者的密碼。如果運作su bill指令,将需要輸入bill的密碼。

繼續閱讀