Sublime Text 无法在没有 `-E` 的情况下使用 `sudo` 运行

Sublime Text 无法在没有 `-E` 的情况下使用 `sudo` 运行

我想我对我的设置造成了一些损坏,因为现在我无法在没有以下命令的情况下以 root 身份运行 Sublime Text -E

subl //works
sudo subl //doesn't work (no errors, just silence)
sudo -E subl //works.

我怎样才能解决这个问题?


输出env

XDG_VTNR=7
LC_PAPER=uk_UA.UTF-8
LC_ADDRESS=uk_UA.UTF-8
XDG_SESSION_ID=c2
XDG_GREETER_DATA_DIR=/var/lib/lightdm-data/daria
LC_MONETARY=uk_UA.UTF-8
CLUTTER_IM_MODULE=xim
COMP_WORDBREAKS=    
"'><;|&(:
SESSION=ubuntu
TERM=xterm-256color
VTE_VERSION=4002
SHELL=/bin/bash
WINDOWID=69206026
LC_NUMERIC=uk_UA.UTF-8
UPSTART_SESSION=unix:abstract=/com/ubuntu/upstart-session/1000/1341
GNOME_KEYRING_CONTROL=
GTK_MODULES=unity-gtk-module
LC_ALL=
USER=daria
LC_TELEPHONE=uk_UA.UTF-8
XDG_SESSION_PATH=/org/freedesktop/DisplayManager/Session0
XDG_SEAT_PATH=/org/freedesktop/DisplayManager/Seat0
SSH_AUTH_SOCK=/run/user/1000/keyring/ssh
DEFAULTS_PATH=/usr/share/gconf/ubuntu.default.path
XDG_CONFIG_DIRS=/etc/xdg/xdg-ubuntu:/usr/share/upstart/xdg:/etc/xdg
DESKTOP_SESSION=ubuntu
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
LC_MESSAGES=en_US.UTF-8
QT_IM_MODULE=ibus
QT_QPA_PLATFORMTHEME=appmenu-qt5
LC_COLLATE=en_US.UTF-8
LC_IDENTIFICATION=uk_UA.UTF-8
XDG_SESSION_TYPE=x11
PWD=/home/daria
JOB=unity-settings-daemon
XMODIFIERS=@im=ibus
GNOME_KEYRING_PID=
LANG=en_US.UTF-8
GDM_LANG=en
MANDATORY_PATH=/usr/share/gconf/ubuntu.mandatory.path
LC_MEASUREMENT=uk_UA.UTF-8
COMPIZ_CONFIG_PROFILE=ubuntu
IM_CONFIG_PHASE=1
PAPERSIZE=a4
GDMSESSION=ubuntu
SESSIONTYPE=gnome-session
GTK2_MODULES=overlay-scrollbar
SHLVL=1
HOME=/home/daria
XDG_SEAT=seat0
LANGUAGE=en
GNOME_DESKTOP_SESSION_ID=this-is-deprecated
UPSTART_INSTANCE=
UPSTART_EVENTS=xsession started
XDG_SESSION_DESKTOP=ubuntu
LOGNAME=daria
COMPIZ_BIN_PATH=/usr/bin/
XDG_DATA_DIRS=/usr/share/ubuntu:/usr/share/gnome:/usr/local/share/:/usr/share/
QT4_IM_MODULE=xim
LC_CTYPE=en_US.UTF-8
DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-B8OeFaNcXl
LESSOPEN=| /usr/bin/lesspipe %s
INSTANCE=
UPSTART_JOB=unity7
XDG_RUNTIME_DIR=/run/user/1000
DISPLAY=:0
XDG_CURRENT_DESKTOP=Unity
GTK_IM_MODULE=ibus
LESSCLOSE=/usr/bin/lesspipe %s %s
LC_TIME=uk_UA.UTF-8
LC_NAME=uk_UA.UTF-8
XAUTHORITY=/home/daria/.Xauthority
_=/usr/bin/env

输出sudo env

LC_PAPER=uk_UA.UTF-8
LC_ADDRESS=uk_UA.UTF-8
LC_MONETARY=uk_UA.UTF-8
TERM=xterm-256color
LC_NUMERIC=uk_UA.UTF-8
LC_ALL=
LC_TELEPHONE=uk_UA.UTF-8
LC_MESSAGES=en_US.UTF-8
LC_COLLATE=en_US.UTF-8
LC_IDENTIFICATION=uk_UA.UTF-8
LANG=en_US.UTF-8
LC_MEASUREMENT=uk_UA.UTF-8
LANGUAGE=en
LC_CTYPE=en_US.UTF-8
LC_TIME=uk_UA.UTF-8
LC_NAME=uk_UA.UTF-8
SHELL=/bin/bash
MAIL=/var/mail/root
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
LOGNAME=root
USER=root
USERNAME=root
HOME=/root
SUDO_COMMAND=/usr/bin/env
SUDO_USER=daria
SUDO_UID=1000
SUDO_GID=1000

内容/etc/sudoers

#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults    env_reset
Defaults    mail_badpass
Defaults    secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
Defaults    env_keep="https_proxy"

# Host alias specification

# User alias specification

# Cmnd alias specification

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

# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL

# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL

# See sudoers(5) for more information on "#include" directives:

#includedir /etc/sudoers.d

daria ALL=NOPASSWD: ALL
root    ALL=(ALL)   ALL

答案1

问题出在sudo命令设置的环境中。

由于此行,设置了非功能性环境/etc/sudoers

Defaults env_keep="https_proxy"

它以不同的方式影响环境,例如:

  • DISPLAY并且XAUTHORITY未设置(导致问题)
  • HOME设置/home/root

并且可能还有其他方式。

如果您希望https_proxy在运行时保留先前的环境sudo(这通常很有用,以便能够在运行时使用代理apt-get),请将该行更改为以下行:

Defaults env_keep+="https_proxy"

这样其他需要的环境变量就不会被取消设置。

否则,如果您没有理由https_proxy在运行时保留先前的环境sudo,那么您可以直接删除整行。

相关内容