Debian小问题:sudo不能使用

本文介绍了在Debian系统中解决sudo权限问题的方法,通过编辑sudoers文件为普通用户分配sudo权限,并展示了如何使用sudo命令及配置环境变量来运行特定服务。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

今天本打算用Debian做负载均衡测试,结果发现:
[quote]
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.[/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]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[/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]了!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值