歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> 關於Linux >> CentOS下添加普通用戶到sudo組,並且免密碼登錄

CentOS下添加普通用戶到sudo組,並且免密碼登錄

日期:2017/3/1 11:56:46   编辑:關於Linux

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權限。

[dba@oracle ~]$ 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.
[dba@oracle ~]$ 

使用 “su –” 命令,進入root用戶;為sudoers文件添加寫入的權限:使用命令 “chmod u+w /etc/sudoers”執行visudo 命令,按“i”進入編輯模式後,找到“root ALL=(ALL) ALL ”,在後面添加:"dba ALL=(ALL) NOPASSWD: ALL",再按一下“Esc”鍵退出編輯,輸入“wq”(write quit)後,退出sudoers。ss輸入“chmod u-w /etc/sudoers”將文件的寫入屬性去掉通過“exit”切換回自己的用戶,再使用sudo whoami命令時,如果返回root,就可以使用了

Copyright © Linux教程網 All Rights Reserved