使用SUDO时如何保持环境变量 [英] How to keep Environment Variables when Using SUDO

查看:137
本文介绍了使用SUDO时如何保持环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用sudo命令时,环境变量不存在。例如,在设置HTTP_PROXY之后,命令 wget 可以正常工作,而没有 sudo 。但是如果我键入 sudo wget ,它表示它不能绕过代理设置。

解决方案

诀窍是通过 sudo visudo 命令将环境变量添加到 sudoers 文件,并添加以下行:

 默认值env_keep + =ftp_proxy http_proxy https_proxy no_proxy
ArchLinux wiki 的p>



对于Ubuntu 14,您需要在单行中指定,因为它返回多变量行的错误:

 默认值env_keep + =http_proxy
默认值env_keep + =https_proxy
默认值env_keep + =HTTP_PROXY
默认值env_keep + =HTTPS_PROXY


When I use any command with sudo the enviroment variables are not there. For example after setting HTTP_PROXY the command wget works fine without sudo. However if I type sudo wget it says it can't bypass the proxy setting.

解决方案

The trick is to add environment variables to sudoers file via sudo visudo command and add these lines:

Defaults env_keep += "ftp_proxy http_proxy https_proxy no_proxy"

taken from ArchLinux wiki.

For Ubuntu 14, you need to specify in separate lines as it returns the errors for multi-variable lines:

Defaults  env_keep += "http_proxy"
Defaults  env_keep += "https_proxy"
Defaults  env_keep += "HTTP_PROXY"
Defaults  env_keep += "HTTPS_PROXY"

这篇关于使用SUDO时如何保持环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆