用户不在sudoers文件中的解决方法 .

来源:互联网 发布:德雷克斯勒生涯数据 编辑:程序博客网 时间:2024/06/06 13:23
在使用Linux系统过程中,通常情况下,我们都会使用普通用户进行日常操作,而root用户只有在权限分配及系统设置时才会使用,而root用户的密码也不可能公开。普通用户执行到系统程序时,需要临时提升权限,sudo就是我们常用的命令,仅需要输入当前用户密码,便可以完成权限的临时提升。在使用sudo命令的过程中,我们经常会遇到当前用户不在sudoers文件中的提示信息,如果解决该问题呢?通过下面几个步骤,可以很简单的解决此问题。

    1、切换到root用户权限

Last login: Tue Sep 24 20:50:51 2013 from 192.168.30.171
[user@Compile ~]$ su root
密码:
[root@Compile user]#

    2、查看/etc/sudoers文件权限,如果只读权限,修改为可写权限

[root@Compile user]# ls -l /etc/sudoers
-r--r-----. 1 root root 4030 9月  25 00:57 /etc/sudoers
[root@Compile user]# chmod 777 /etc/sudoers
[root@Compile user]# ls -l /etc/sudoers
-rwxrwxrwx. 1 root root 4030 9月  25 00:57 /etc/sudoers
[root@Compile user]#

    3、执行vi命令,编辑/etc/sudoers文件,添加要提升权限的用户;在文件中找到root ALL=(ALL) ALL,在该行下添加提升权限的用户信息,如:

root    ALL=(ALL)       ALL
user    ALL=(ALL)       ALL

说明:格式为(用户名    网络中的主机=(执行命令的目标用户)    执行的命令范围)

    4、保存退出,并恢复/etc/sudoers的访问权限为440

[root@Compile user]# chmod 440 /etc/sudoers
[root@Compile user]# ls -l /etc/sudoers
-r--r-----. 1 root root 4030 9月  25 00:57 /etc/sudoers
[root@Compile user]#

    5、切换到普通用户,测试用户权限提升功能..

 

另外有以下方法

1、添加用户,首先用adduser命令添加一个普通用户,命令如下:
#adduser tommy      //添加一个名为tommy的用户
#passwd tommy       //修改密码
Changing password for user tommy.
New UNIX password:                //在这里输入新密码
Retype new UNIX password:         //再次输入新密码
passwd: all authentication tokens updated successfully.

2、赋予root权限
方法一: 修改 /etc/sudoers 文件,找到%wheel一行,把前面的注释(#)去掉
## Allows people in group wheel to run all commands
%wheel    ALL=(ALL)    ALL
然后修改用户,使其属于root组(wheel),命令如下:
#usermod -g root tommy
修改完毕,现在可以用tommy帐号登录,然后用命令 sudo su - ,即可获得root权限进行操作。
方法二: 修改 /etc/sudoers 文件,找到root一行,在root下面添加一行,如下所示:
## Allow root to run any commands anywhere
root    ALL=(ALL)     ALL
tommy   ALL=(ALL)     ALL
修改完毕,现在可以用tommy帐号登录,然后用命令 sudo su - ,即可获得root权限进行操作。
方法三: 修改 /etc/passwd 文件,找到如下行,把用户ID修改为 0 ,如下所示:
tommy:x:500:500:tommy:/home/tommy:/bin/bash
修改后如下
tommy:x:0:500:tommy:/home/tommy:/bin/bash
保存,用tommy账户登录后,直接获取的就是root帐号的权限。

建议使用方法二,不要轻易使用方法三。
本篇文章来源于 Linux公社网站(
www.linuxidc.com)  原文链接:http://www.linuxidc.com/Linux/2012-07/64530.htm

 

0 0
原创粉丝点击