2014年12月2日 星期二

Linux sudo 加入使用者

步驟1.
用root權限加入#useradd UserXXX  (不會主動建立家目錄)
若已建立過user會出現#useradd: user 'UserXXX ' already exists

步驟2.
設定密碼passwd UserXXX 
輸入新的 UNIX 密碼:
再次輸入新的 UNIX 密碼:
passwd:密碼已成功地變更

此時尚未加入sudoers檔案
執行#sudo UserXXX出現
#UserXXX is not in the sudoers file.  This incident will be reported.
步驟3.
編輯vi /etc/sudoers 或
執行 #visudo(編輯/etc/sudoers.tmp)
root ALL=(ALL) ALL這行底下加入
UserXXX ALL=(ALL) ALL

sudo adduser  sudo
The change will take effect the next time the user logs in.
This works because /etc/sudoers is pre-configured to grant permissions to all members of this group (You should not have to make any changes to this):
# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL
As long as you have access to a user that is in the same groups as your "original" user, you can delete the old one.

Realistically, there are also other groups your new user should be a member of. If you set the Account type of a user to Administrator in Users Settings, it will be placed in at least all of these groups:
adm sudo lpadmin sambashare
Because your system configuration may vary, I suggest taking a look at the output of groups  to see what groups are normally in use.

Open a Root Terminal and type visudo (to access and edit the list).
Navigate to the bottom of the sudoers file that is now displayed in the terminal.
Just under the line that looks like the following:
    root ALL=(ALL) ALL
Add the following (replacing user with your actual username):
    user ALL=(ALL) ALL
Now save the file. The procedure for this will depend on your editor:
  • nano – CtrlO then Enter, then CtrlX to exit
  • vim – :wq

參考
sudo-user

How can I add a new user as sudoer using the command line?

My main username is not in the sudoers file


沒有留言:

張貼留言