ubuntu 添加sudo使用者

來源:互聯網
上載者:User

轉載: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使用者下執行上面所有的操作

聯繫我們

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