因为这个,我最近遇到了麻烦。
$sudo vim /etc/motd
[sudo] password for bruce:
bruce is not in the sudoers file. This incident will be reported.
Run Code Online (Sandbox Code Playgroud)
有没有办法检查我是否有 sudo 访问权限?
上次,我询问了这些(在/etc/sudoers中)的风险:
user_name ALL=(ALL) /usr/bin/vim /etc/httpd/confs/httpd.conf
%group_name ALL=(ALL) /usr/bin/vim /etc/httpd/confs/httpd.conf
Run Code Online (Sandbox Code Playgroud)
在思考这个问题的时候,我找到了/etc/sudoers.d目录。目录下的文件应该和/etc/sudoers有类似的功能(也就是说上面的脚本在/etc/sudoers.d里还是有问题的),但是有一篇文章说我们不应该使用这个目录,因为我们不能用它visudo来编辑文件它。也就是说,sudo如果我们在目录中出错,我们将失去使用权。
如果这是真的,为什么我们有/etc/sudoers.d?或者我们有没有好的方法来编辑/etc/sudoers.d 中的文件?
我遇到以下错误,试图在运行时允许某些环境变量传递到新环境sudo:
sudo: sorry, you are not allowed to preserve the environment
Run Code Online (Sandbox Code Playgroud)
一些可能有助于调试的信息:
[deploy@worker1 ~]$ sudo -l
Matching Defaults entries for deploy on this host:
requiretty, !visiblepw, always_set_home, env_reset, env_keep="COLORS DISPLAY HOSTNAME HISTSIZE INPUTRC KDEDIR LS_COLORS", env_keep+="MAIL PS1 PS2 QTDIR USERNAME LANG LC_ADDRESS LC_CTYPE",
env_keep+="LC_COLLATE LC_IDENTIFICATION LC_MEASUREMENT LC_MESSAGES", env_keep+="LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE", env_keep+="LC_TIME LC_ALL LANGUAGE LINGUAS _XKB_CHARSET
XAUTHORITY", secure_path=/sbin\:/bin\:/usr/sbin\:/usr/bin, env_keep+="GIT_WORK_TREE GIT_DIR", !requiretty
User deploy may run the following commands on this host:
(ALL) NOPASSWD: /usr/bin/git, (ALL) /etc/init.d/httpd*, (ALL) …Run Code Online (Sandbox Code Playgroud) 最近,我通过 /etc/hostname.conf 更改了 sudoers 文件和主机名。更改此文件后,我的 sudo 命令需要花费大量时间。此外,它说 sudo 无法解析主机 kaagini(我机器的主机名)。
为什么 sudo 必须知道主机名才能为某些东西提供权限?
我的 sudoers 文件有一个命令“默认值 env_reset”。我看到了一些类似的问题,但这里的上下文不是远程登录。错误显示在本地主机上。
该问题的初始谷歌搜索表明 /etc/hosts 文件必须具有 127.0.0.1 的实际主机名。这解决了我的问题。但我的实际问题是:为什么我们需要这个 sudo ?无论登录位置如何,sudo 都应该工作。
我正在使用 Ubuntu 10.04 Server 并尝试设置 sudoers 以尊重用户的 EDITOR 选择(在限制范围内)
在我的 sudoers 中,我有:
Defaults editor=/usr/bin/nano:/usr/bin/vim
Defaults env_reset
Run Code Online (Sandbox Code Playgroud)
在用户 .bashrc 中:
export EDITOR=/usr/bin/vim
Run Code Online (Sandbox Code Playgroud)
$EDITOR 设置:
$ echo $EDITOR
/usr/bin/vim
Run Code Online (Sandbox Code Playgroud)
根据man sudoers这应该足以将 $EDITOR 设置为 vim:
editor A colon (':') separated list of editors allowed to be used with visudo.
visudo will choose the editor that matches the user's EDITOR environment
variable if possible, or the first editor in the list that exists and is
executable. The default is the path to …Run Code Online (Sandbox Code Playgroud) 每个 ALL 是什么意思?我知道整行都表明 admin 组成员获得了 admininstartive 权限,但想了解有关 ALLS 位置的更多信息,以及他们是否各自引用不同的权限集或类似的内容?
$sudo cat /etc/sudoers
...
# User privilege Information
root ALL=(ALL) ALL
#...
%sudo ALL=(ALL) ALL
#
#includedir /etc/sudoers.d
#Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL
#
Run Code Online (Sandbox Code Playgroud)
如果重要:操作系统:Ubuntu:10.4
在我的 sudoers 文件中,有以 开头的#行、以 开头的%行和不以两者开头的行。该#肯定是被用来注释掉线,但到底是什么的%呢?它也是评论标记吗?
我已经在Stack Overflow 中问过这个问题,但我被要求在这里发布。所以做同样的事情。
我使用我的java程序运行了这个命令-
sudo -u <username> -S pwd
Run Code Online (Sandbox Code Playgroud)
我得到了这个输出-
command=sudo -u <username> -S pwd
exitCode=1
sudo: sorry, you must have a tty to run sudo
Run Code Online (Sandbox Code Playgroud)
我尝试编辑 /etc/sudoers 但它已经包含
<username> ALL=(ALL) NOPASSWD: ALL
Run Code Online (Sandbox Code Playgroud)
然后,我了解到这可以通过在 /etc/sudoers 中注释掉以下代码来完成
# Defaults requiretty
Run Code Online (Sandbox Code Playgroud)
此外,默认情况下,当尝试以其他用户身份使用 执行命令时sudo,我们必须提供自己的密码。但这可以通过在 /etc/sudoers- 中进行以下更改来更改
Defaults targetpw
Run Code Online (Sandbox Code Playgroud)
我的问题是,是否可以在 Java 中执行我的上述命令而无需在任何地方进行任何更改,即通过默认设置?
我正在尝试添加一个新的管理员用户,但是:
# adduser username admin
adduser: The user `username' does not exist.
# man sudoers
No manual entry for sudoers
# less /etc/sudoers
/etc/sudoers: No such file or directory
Run Code Online (Sandbox Code Playgroud)
系统是 Debian 7 (Wheezy) 我做错了什么?
(在 Centos 上通过 Docker)
我知道我可以使用visudo. 有没有办法直接从命令行将用户添加到 sudoer 列表中,这样我就不必以交互方式进行操作?
我之所以这么问,是因为我正在尝试配置不具有交互性的 Docker centos 容器。