sudo网络权限
2016-12-14 23:21
127 查看
背景
对于设置了网络代理的服务器,在当前用户下执行网络访问没有问题,但通过sudo执行命令时,就会出现“无网络连接”的错误。普通权限下,wget成功。 # wget https://github.com --2016-12-08 09:00:43-- https://github.com/ Connecting to 109.105.113.200:8080... connected. Proxy request sent, awaiting response... 200 OK Length: unspecified [text/html] Saving to: ‘index.html’ 2016-12-08 09:01:03 (1.33 KB/s) - ‘index.html’ saved [25692] 使用sudo命令后,连接失败。 # sudo wget https://github.com --2016-12-08 09:01:41-- https://github.com/ Resolving github.com (github.com)... failed: Name or service not known. wget: unable to resolve host address ‘github.com’
解决方案
出现这种情况的原因,是因为sudo命令的作用是为了允许普通用户使用超级用户权限的工具,但却没有继承来自环境变量。而网络代理的设置,是通过设置http_proxy,https_proxy等环境变量来实现的。因此,sudo后也就失去了网络代理,自然也就没有了网络连接。为了解决该问题,我们需要修改sudo的配置文件。修改sudo的配置文件有特殊的命令和方法,具体参考http://blog.163.com/clevertanglei900@126/blog/static/111352259201142621547160/,我这里不做详细介绍了。在sudo的配置文件中,增加Defaults env_keep += “http_proxy https_proxy”。该行表示使用sudo命令时,保存后面列出的环境变量。
增加配置后,sudo可访问网络。 # sudo wget https://github.com --2016-12-08 09:02:52-- https://github.com/ Connecting to 109.105.113.200:8080... connected. Proxy request sent, awaiting response... 200 OK Length: unspecified [text/html] Saving to: ‘index.html.1’ 2016-12-08 09:02:56 (20.1 KB/s) - ‘index.html.1’ saved [25692]
相关文章推荐
- sudo网络权限
- Linux 下sudo网络权限详解
- ASP.NET设计网络硬盘之创建文件夹与设置权限
- 如何实现网间互访(没有网络服务器权限) 大家提提建议 共同探讨一下
- 网络中无法访问XP系统下共享文件,错误:计算机无法访问,您可能没有权限使用网络资源
- 取消网络访问权限
- 用户权限分配--网络参考资料收集
- 利用sudo命令为Ubuntu分配管理权限
- 解决“你可能没有权限使用网络资源”的问题
- 您可能没有权限使用网络资源。请与这台服务器的管理员联系以查明您是否有访问权限,拒绝访问
- 取消网络访问权限
- 关于xp_cmdshell存储过程的网络访问权限及sp_procoption的用法
- 您可能没有权限使用网络资源。请与这台服务器的管理员联系以查明您是否有访问权限,拒绝访问
- 网络层访问权限控制技术-ACL详解 (2)
- "计算机无法访问,您可能没有权限使用网络资源.请与这台服务器的管理员联系"的解决办法
- 无法访问!你可能没有权限使用网络资源请与这台服。。。!
- 无权限访问网络资源
- Windows系统没有权限访问网络(原创)
- 关于补充《网络管理规定》“上网权限管理”办法实施细节
- 【转】您可能没有权限使用网络资源,请与这台服务器的管理员联系以查明您是否有访问权限" 的解决办法