1. 程式人生 > >ubuntu 新增sudo使用者

ubuntu 新增sudo使用者

轉載:http://hi.baidu.com/it_master/blog/item/07b1ac390f7c793ab9998f41.html

第一種方法: 新增sudo使用者

當你安裝Ubuntu的時候,它會自動新增第一個使用者到sudo組,允許這個使用者通過鍵入其自身帳戶密碼來獲得超級使用者(root)身份。然而,系統不會再自動新增其他的使用者到sudo組當中去。如果你想在你的共享系統上授予某人某些超級使用者特權,你必須給予他們sudo權利。   

要新增新使用者到sudo,最簡單的方式就是使用 usermod 命令。執行
$sudo usermod -G admin username
這就你要作的,然而,如果使用者已經是其他組的成員,你需要新增 -a 這個選項,象這樣
$sudo usermod -a -G admin username

如果你更喜歡圖形介面來操作這些,使用 “系統 -> 管理 -> 使用者和組”。 選擇你想新增到sudo組的使用者,點選“屬性”,在使用者許可權的區域,選擇“執行系統管理任務”的選擇框即可。


第二種方法:
將使用者新增到sudo組且不輸入密碼

有時候我們只需要執行一條root許可權的命令也要su到root,是不是有些不方便?這時可以用sudo代替
fedora預設新建的使用者不在sudo組,需要編輯/etc/sudoers檔案將使用者加入,該檔案只能使用visudo命令,首先需要切換到root
su -   (注意有- ,這和su是不同的,在用命令"su"的時候只是切換到root,但沒有把root的環境變數傳過去,還是當前用乎的環境變數,用"su -"命令將環境變數也一起帶過去,就象和root登入一樣)
然後
visudo
這個和vi的用法一樣,由於可能會有人不太熟悉vi,所以簡要說一下步驟
移動游標,到最後一行,按a,進入append模式,輸入
your_user_name ALL=(ALL)
然後按Esc,再輸入:w儲存檔案,再:q退出
這樣就把自己加入了sudo組,可以使用sudo命令了。
如果覺得在sudo的時候輸入密碼麻煩,把剛才的輸入換成如下內容即可:
your_user_name ALL=(ALL)NOPASSWD: ALL
至於安全問題,對於一般個人使用者,我覺得這樣也可以的。

如果因為某種原因,當嘗試用sudo的時候出現了以下錯誤,sudo: /etc/sudoers is mode 0777, should be 0440。這是因為sudoers配置檔案讀寫許可權出了問題。下面是從國外的網站上找到的解決方法。

jasongroome

When I try to use the sudo command in terminal I get the following error message:

sudo: /etc/sudoers is mode 0777, should be 0440

Any help with this would be greatly appreciated.

gowrann

the privileges of this file are incorrect they should be owner=read group=read and everyone=nothing, this translates to 440 at the moment you have 777 which gives owner/group & everyone read/write and execute privileges.

To change the privileges log in as root;

[localhost:/Users/neilgowr] root# cd /etc
[localhost:/etc] root# chmod 440 sudoers
[localhost:/etc] root# ls -l sudoers
-r--r----- 1 root wheel 315 Sep 3 2001 sudoers

this will fix it for you.

jasongroome

thanks a lot, it worked a treat.


說明:以上必須用root使用者登入進去才可以修改,如果不知道root可以通過當前具有sudo許可權的使用者更改root使用者密碼,相應命令:sudo passwd root,會提示你輸入當前使用者密碼及兩次root使用者新密碼;修改密碼完成後,可以通過su - root命令切換到root使用者下執行上面所有的操作