mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-01-25 23:11:02 +08:00
Finish translate
20140716 Linux FAQs with Answers--How to define PATH environment variable for sudo commands
This commit is contained in:
parent
5a0db84196
commit
41d5a4fe0c
@ -1,43 +0,0 @@
|
||||
nd0104 is translate
|
||||
Linux FAQs with Answers--How to define PATH environment variable for sudo commands
|
||||
================================================================================
|
||||
> **Question**: I built and installed a program in /usr/local/bin. The program requires root privilege to run. But when I try to run the program with sudo, I get "sudo: XXXXX: command not found" error. Somehow /usr/local/bin is not included in the PATH environment variable. How can I fix this problem?
|
||||
|
||||
When you run a program with sudo, the program is executed with a new, minimum environment for security reasons. That is, not all the environment variables you define are inherited to sudo commands. In case of PATH environment variable, it is reset to a new "default" PATH variable when sudo is used. So if the new default PATH variable does not include the folder where your program is, you will get "command not found" error with sudo.
|
||||
|
||||
To customize the default PATH variable for sudo session, open /etc/sudoers file with a text editor, and look for "secure_path". The value defined in "secure_path" will be used as the default PATH variable when you execute sudo commands.
|
||||
|
||||
So add any necessary path (e.g., /usr/local/bin) to "secure_path", and it will be passed to sudo commands.
|
||||
|
||||
Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin
|
||||
|
||||
This change will be effective immediately.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://ask.xmodulo.com/define-path-environment-variable-sudo-commands.html
|
||||
|
||||
译者:[译者ID](https://github.com/译者ID) 校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
|
||||
|
||||
[1]:
|
||||
[2]:
|
||||
[3]:
|
||||
[4]:
|
||||
[5]:
|
||||
[6]:
|
||||
[7]:
|
||||
[8]:
|
||||
[9]:
|
||||
[10]:
|
||||
[11]:
|
||||
[12]:
|
||||
[13]:
|
||||
[14]:
|
||||
[15]:
|
||||
[16]:
|
||||
[17]:
|
||||
[18]:
|
||||
[19]:
|
||||
[20]:
|
@ -0,0 +1,23 @@
|
||||
|
||||
Linux 常见问题(有答案的哦)-- 如何为sudo命令定义PATH环境变量
|
||||
================================================================================
|
||||
>**问题**:我安装了一个程序到/usr/local/bin目录下,这个程序需要root权限才能执行,当我用sudo去执行它时,收到"sudo: XXXXX: command not found"的错误提示,不知道为什么/usr/local/bin没有被包含到PATH环境变量下面来,我该如何解决这个问题?
|
||||
|
||||
当你使用sudo去执行一个程序时,处于安全的考虑,这个程序将在一个新的、最小化的环境中执行,也就是说,诸如PATH这样的环境变量,在sudo命令下已经被重置成默认状态了。
|
||||
所以当一个刚初始化的PATH变量中不包含你所要运行的程序所在的目录,你就会得到"command not found"的错误提示。
|
||||
|
||||
为了改变PATH在sudo会话中的初始值,打开/etc/sudoers文件并编辑,找到"secure_path"一行,"secure_path"中包含的路径就将在sudo会话中的PATH变量中生效。
|
||||
|
||||
添加所需要的路径(如 /usr/local/bin)到"secure_path"下,在开篇所遇见的问题就将迎刃而解。
|
||||
Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin
|
||||
|
||||
|
||||
这个修改会即刻生效。
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://ask.xmodulo.com/define-path-environment-variable-sudo-commands.html
|
||||
|
||||
译者:[nd0104](https://github.com/nd0104) 校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
|
||||
|
Loading…
Reference in New Issue
Block a user