Debian小问题:sudo不能使用

今天本打算用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用户:
su


visudo

实际上是编辑 /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


再次执行命令:
引用
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


有的时候需要使用到一些服务,譬如使用service命令,启动一些服务,可以这样做:
vim .bashrc

引用
# .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

# User specific aliases and functions
export PATH=$PATH:/sbin;

注意加入最后一行 export PATH=$PATH:/sbin;,就可以使用 /sbin/service了!

猜你喜欢

转载自snowolf.iteye.com/blog/745997