1. 程式人生 > >adduser Ubuntu添加sudo用戶

adduser Ubuntu添加sudo用戶

剛才 not 環境變量 喜歡 使用 提示 移動 ann ive

第一種方法: 添加sudo用戶

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

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

即 # usermod -aG sudo develon


如果你更喜歡圖形界面來操作這些,使用 “系統 -> 管理 -> 用戶和組”。 選擇你想添加到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用戶下執行上面所有的操作

adduser Ubuntu添加sudo用戶