Debian小问题:sudo不能使用

Debian小问题:sudo不能使用

转自:http://snowolf.javaeye.com/blog/745997

文章分类:操作系统 今天本打算用Debian做负载均衡测试,结果发现:

引用

zlex@localhost:~/Desktop$ sudo apt-get install tomcat6

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 zlex:
zlex is not in the sudoers file.  This incident will be reported.


sudo不能使用?!顿时无语!
Google搜索无数,发现:
xxx is not in the sudoers file.  This incident will be reported.
linux默认没有为当前用户开启sudo权限!
切换到root用户:

Shell代码  
  1. su  


修改 /etc/sudoers 文件编写权限:

Shell代码  
  1. chmod u+w /etc/sudoers  


编辑该文件:

Shell代码  
  1. vi /etc/sudoers  


zlex    ALL=(ALL) ALL 加入其中:

引用


# /etc/sudoers
#
# This file MUST be edited with the 'visudo' command as root.
#
# See the man page for details on how to write a sudoers file.
#

Defaults        env_reset

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root    ALL=(ALL) ALL
zlex    ALL=(ALL) ALL

# Uncomment to allow members of group sudo to not need a password
# (Note that later entries override this, so you might need to move
# it further down)
# %sudo ALL=NOPASSWD: ALL



还原/etc/sudoers 文件编写权限,并退出:

Shell代码  
  1. chmod u-w /etc/sudoers  
  2. exit  



再次执行命令:

引用
zlex@localhost:~/Desktop$ sudo apt-get install tomcat6

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 zlex:
正在读取软件包列表... 完成
正在分析软件包的依赖关系树      
正在读取状态信息... 完成      
E: 无法找到软件包 tomcat6



sudo终于可以用了!


有时候我们只需要执行一条root权限的命令也要su到root,是不是有些不方便?这时可以用sudo代替。

补充:
使用visudo命令 ,移动光标,找到root    ALL=(ALL)       ALL 一行,按a,进入append模式,输入your_user_name ALL=(ALL) ,然后按Esc,再输入:w保存文件,再:q退出。这样就把自己加入了sudo组,可以使用sudo命令了。

如果觉得在sudo的时候输入密码麻烦,把刚才的输入换成your_user_name ALL=(ALL)NOPASSWD: ALL

你可能感兴趣的:(Linux,debian,shell,tomcat,user,负载均衡,command)