歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> CentOS 系統sudo命令配置

CentOS 系統sudo命令配置

日期:2017/2/28 15:43:27   编辑:Linux教程

在linux系統中,由於root的權限過大,一般情況都不使用它。只有在一些特殊情況下才采用登錄root執行管理任務,一般情況下臨時使用root權限多采用su和sudo命令。

一、su和sudo命令對比:

在普通用戶下輸入su命令後,會提示輸入root賬戶的密碼,然後就進入特權模式(跟用root登錄系統完全一樣),輸入exit或者su - user 退出:

$su

Password:

#ls /root

anaconda-ks.cfg install.log install.log.syslog

#exit

$ls /root

ls: cannot open directory /root: Permission denied #提示沒有權限 【Linux公社 http://www.linuxidc.com 】

而采用sudo命令,只需輸入當前用戶的密碼(也可以配置為不輸入密碼)即可執行需要root權限執行的命令:

$ls /root

ls: cannot open directory /root: Permission denied #提示沒有權限

$sudo ls /root

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 Oracle: #輸入普通用戶oracle的密碼

anaconda-ks.cfg install.log install.log.syslog

通過上面的對比可以看出,sudo比su有很多優點:

1、普通用戶不需要知道root的密碼即可執行需要root權限的命令;

2、不會因忘記退出而采用root執行了會引起破壞性的命令(初學linux經常犯這個錯);

Copyright © Linux教程網 All Rights Reserved