码迷,mamicode.com
首页 > 其他好文 > 详细

sudo用户免输sudo密码

时间:2015-09-22 18:59:08      阅读:327      评论:0      收藏:0      [点我收藏+]

标签:redhat   centos   sudo   

最近一直在查如何创建sudo用户并且免输sudo密码,找了很多资料,结果发现不可行。然后今天意外的被我破解了!

环境:  CentOS 6.6 

1. 首先你的有一个执行sudo的普通用户。  

[root@WEB2 ~]# useradd chengcai

2. 以root用户登录,然后修改/etc/sudoers文件:

vim /etc/sudoers    

####################################################################

## Allow root to run any commands anywhere 

root    ALL=(ALL)       ALL


## Allows members of the ‘sys‘ group to run networking, software, 

## service management apps and more.

# %sys ALL = NETWORKING, SOFTWARE, SERVICES, STORAGE, DELEGATING, PROCESSES, LOCATE, DRIVERS


## Allows people in group wheel to run all commands

# %wheel        ALL=(ALL)       ALL


## Same thing without a password

 %wheel ALL=(ALL)       NOPASSWD: ALL                 #将此行的#删除。

####################################################################

3.  将你的普通用户加入到wheel组中:

[root@WEB2 ~]# usermod -g wheel chengcai              #将chengcai用户加入到wheel组中

4.  修改/etc/sudoers.d/waagent文件中内容:  

[root@WEB2 ~]# vim /etc/sudoers.d/waagent             #由于之前一直没改这个文件,出现第一次用普通用户chengcai执行sudo -i时出现第一次需要输入密码,然后exit退出在执行sudo -i则不需密码。(如图)

技术分享

####################################################################

#chengcai ALL = (ALL) ALL                              #这一行内容中添加免密码如下:

chengcai ALL = (ALL) NOPASSWD:ALL

####################################################################

Remarks:  有可能是系统的问题,对于CentOS在/etc/sudoers.d/下有waagent文件,然而对于RedHat系统却没有这个文件,步骤四只基于CentOS系统,对于RedHat系统只需前三步即可。

5. 验证:用普通用户登录,然后输入sudo -i或sudo su root不需要密码。

技术分享

本文出自 “Aestheticism” 博客,请务必保留此出处http://cctian.blog.51cto.com/10445650/1697177

sudo用户免输sudo密码

标签:redhat   centos   sudo   

原文地址:http://cctian.blog.51cto.com/10445650/1697177

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!