欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Debian小问题:sudo不能使用

程序员文章站 2022-05-10 09:45:56
...
今天本打算用Debian做负载均衡测试,结果发现:
[quote]
[email protected]:~/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.[/quote]
sudo不能使用?!顿时无语!
Google搜索无数,发现:
[b]xxx is not in the sudoers file. This incident will be reported.[/b]
linux默认没有为当前用户开启sudo权限!
切换到root用户:
su


visudo

实际上是编辑[b]/etc/sudoers[/b]文件
将[b]zlex ALL=(ALL) ALL[/b]加入其中:
[quote]

# /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
[/quote]

再次执行命令:
[quote][email protected]:~/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[/quote]

sudo终于可以用了! :D


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

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

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

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

[quote]# .bashrc

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

# User specific aliases and functions
export PATH=$PATH:/sbin;[/quote]
注意加入最后一行[b]export PATH=$PATH:/sbin;[/b],就可以使用[b]/sbin/service[/b]了!
相关标签: Linux sudo