1. 程式人生 > >CentOS下新增普通使用者到sudo組,並且免密碼登入

CentOS下新增普通使用者到sudo組,並且免密碼登入

1.1 sudo

         Sudo是linux系統中,非root許可權的使用者提升自己許可權來執行某些特性命令的方式,它使普通使用者在不知道超級使用者的密碼的情況下,也可以暫時的獲得root許可權。
         一般,普通使用者在執行特殊命令是,只需要在特殊命令(如 yum)前面加上sudo,並輸入自己的使用者密碼就可以了,在之後的5分鐘內,再次使用特殊命令時,就無需再次輸入使用者密碼。
         同時,sudo提供了強大的日誌管理,其中詳細的記錄了每個使用者都幹了什麼。

         sudo使用者的管理是在檔案:/etc/sudoers中存放的。也就是說,如果想把某個使用者加入到sudo使用者群裡面,就需要自行配置這個檔案,在讀寫這個檔案時,需要root的許可權。

1.2 將使用者新增到sudo組

         在使用sudo的時候,如果出現"dba is not in the sudoers file. This incident will be reported.”說明當前使用者名稱:dba是沒有許可權使用sudo的,這個時候我們就需要修改/etc/sudoers來為當前使用者dba新增sudo許可權。
[[email protected] ~]$ sudo yum -y update

We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.

[sudo] password for dba: 
dba is not in the sudoers file.  This incident will be reported.
[
[email protected]
~]$
  1. 使用 “su –” 命令,進入root使用者;
  2. 為sudoers檔案新增寫入的許可權:使用命令   “chmod u+w /etc/sudoers”
  3. 執行visudo 命令,按“i”進入編輯模式後,找到“root ALL=(ALL) ALL ”,在後面新增:"dba ALL=(ALL)  NOPASSWD:  ALL",再按一下“Esc”鍵退出編輯,輸入“wq”(write quit)後,退出sudoers。ss
  4. 輸入“chmod u-w /etc/sudoers”將檔案的寫入屬性去掉
  5. 通過“exit”切換回自己的使用者,再使用sudo  whoami命令時,如果返回root,就可以使用了