CentOS 系统sudo命令配置


在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 #提示没有权限 【帮客之家 http://www.bkjia.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经常犯这个错);

  • 1
  • 2
  • 下一页

相关内容