Chinaunix首页 | 论坛 | 博客
  • 博客访问: 101891253
  • 博文数量: 19283
  • 博客积分: 9968
  • 博客等级: 上将
  • 技术积分: 196062
  • 用 户 组: 普通用户
  • 注册时间: 2007-02-07 14:28
文章分类

全部博文(19283)

文章存档

2011年(1)

2009年(125)

2008年(19094)

2007年(63)

分类: LINUX

2008-04-04 20:30:59


有时候我们只需要执行一条root权限的命令也要su到root,是不是有些不方便?这时可以用sudo代替
fedora默认新建的用户不在sudo组,需要编辑/etc/sudoers文件将用户加入,该文件只能使用visudo命令,首先需要切换到root
su -  (注意有- ,这和su是不同的,在用命令"su"的时候只是切换到root,但没有把root的环境变量传过去,还是当前用乎的环境变量,用"su -"命令将环境变量也一起带过去,就象和root登录一样)
然后
visudo
这个和vi的用法一样,由于可能会有人不太熟悉vi,所以简要说一下步骤
移动光标,到最后一行,按a,进入append模式,输入
your_user_name ALL=(ALL)
然后按Esc,再输入:w保存文件,再:q退出
这样就把自己加入了sudo组,可以使用sudo命令了。
如果觉得在sudo的时候输入密码麻烦,把刚才的输入换成如下内容即可:
your_user_name ALL=(ALL)NOPASSWD: ALL
至于安全问题,对于一般个人用户,我觉得这样也可以的。

如果因为某种原因,当尝试用sudo的时候出现了以下错误,sudo: /etc/sudoers is mode 0777, should be 0440。这是因为sudoers配置文件读写权限出了问题。下面是从国外的网站上找到的解决方法。

jasongroome

 

When I try to use the sudo command in terminal I get the following error message:

sudo: /etc/sudoers is mode 0777, should be 0440

Any help with this would be greatly appreciated.

 

gowrann

 

the privileges of this file are incorrect they should be owner=read group=read and everyone=nothing, this translates to 440 at the moment you have 777 which gives owner/group & everyone read/write and execute privileges.

To change the privileges log in as root;

[localhost:/Users/neilgowr] root# cd /etc
[localhost:/etc] root# chmod 440 sudoers
[localhost:/etc] root# ls -l sudoers
-r--r----- 1 root wheel 315 Sep 3 2001 sudoers

this will fix it for you.

 

jasongroome

 

thanks a lot, it worked a treat.

阅读(454) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~