`
yangzb
  • 浏览: 3506958 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

关于LD_LIBRARY_PATH的问题

阅读更多

本人在/etc/environment中设置了环境变量:

JAVA_HOME=/opt/java

ORACLE_HOME=/home/user2/

LD_LIBRARY_PATH=/usr/lib:/usr/local/lib

      正常情况下执行没有问题,但使用sudo XXXXXXX的时候,其他变量都好使,除了LD_LIBRARY_PATH;

 

经探索,找到原因:

 

据说因为安全原因,Linux系统做了限制。
LD_LIBRARY_PATH not loading from .profile nor /etc/environment

     Ubuntu 不能在 profile, environment,.bashrc中设置 LD_LIBRARY_PATH;
解决办法:
     编辑 /etc/ld.so.conf 文件,将指定的路径加上,或者在 /etc/ld.so.conf.d/ 目录中添加一个新的配置文件。

 

分享到:
评论
1 楼 yangzb 2010-02-18  
另一个办法:
The problem is simple: how to preserve PATH and LD_LIBRARY_PATH when running a program via sudo. But when I tried to find a workaround, I was totally confused by related stuff. So I keep a record as clear as possible to help myself.


1.
Topic: How to set environment variables
Source: man sudo, section OPTIONS
Details:

Environment variables to be set for the command may also be passed on the command line in the form of VAR=value,
       e.g.  LD_LIBRARY_PATH=/usr/local/pkg/lib.  Variables passed on the command line are subject to the same restric‐
       tions as normal environment variables with one important exception.  If the setenv option is set in sudoers, the
       command to be run has the SETENV tag set or the command matched is ALL, the user may set variables that would
       overwise be forbidden.  See sudoers(5) for more information.


2.
Topic: About LD_LIBRARY_PATH
Source: man sudo, section SECURITY NOTES
Details:

    Note that the dynamic linker on most operating systems will remove variables that can control dynamic linking from
       the environment of setuid executables, including sudo.  Depending on the operating system this may include _RLD*,
       DYLD_*, LD_*, LDR_*, LIBPATH, SHLIB_PATH, and others.  These type of variables are removed from the environment
       before sudo even begins execution and, as such, it is not possible for sudo to preserve them.


3.
Topic: env_reset
Source: man sudo, section SUDOERS OPTIONS
Details:

env_reset       If set, sudo will reset the environment to only contain the LOGNAME, SHELL, USER, USERNAME and the
                       SUDO_* variables.  Any variables in the caller’s environment that match the env_keep and env_check
                       lists are then added.  The default contents of the env_keep and env_check lists are displayed when
                       sudo is run by root with the -V option.  If sudo was compiled with the SECURE_PATH option, its
                       value will be used for the PATH environment variable.  This flag is on by default.



4.
Topic: Handling environment variables against env_reset
Source: man sudo, section SECURITY NOTES
Details:

      There are two distinct ways to deal with environment variables.  By default, the env_reset sudoers option is
       enabled.  This causes commands to be executed with a minimal environment containing TERM, PATH, HOME, SHELL, LOG‐
       NAME, USER and USERNAME in addition to variables from the invoking process permitted by the env_check and env_keep
       sudoers options.  There is effectively a whitelist for environment variables.

       If, however, the env_reset option is disabled in sudoers, any variables not explicitly denied by the env_check and
       env_delete options are inherited from the invoking process.  In this case, env_check and env_delete behave like a
       blacklist.  Since it is not possible to blacklist all potentially dangerous environment variables, use of the
       default env_reset behavior is encouraged.



My workaround is as follows:

cd /usr/local/bin; sudo ln -s <path_to_my_executable>
sudo LD_LIBRARY_PATH=<path_to_shared_libraries> my_executable

相关推荐

    multi_cuda_exchange.txt

    export LD_LIBRARY_PATH=/usr/local/cuda-10.0/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}} export CUDA_HOME=/usr/local/cuda export PATH=$PATH:$CUDA_HOME/bin export LD_LIBRARY_PATH=/usr/local/cuda-...

    ubuntu9.1随手笔记,GRUB修复,GRUB命令行启动,字体安装,flash 乱码,切换用户,eclipse安装,LD_LIBRARY_PATH变量的设置

    ubuntu9.1随手笔记,GRUB引导修复,GRUB命令行启动,字体安装,flash 乱码,切换用户,eclipse安装,LD_LIBRARY_PATH变量的设置,修改系统启动选项菜单的背景图片,remastersys工具包安装

    mujoco环境变量报错:Missing path to your environment variable.

    为了解决这个问题,我们需要将这个路径添加到`LD_LIBRARY_PATH`中。有几种方法可以实现这一目标: 1. **编辑`.bashrc`文件**:在个人主目录`~`(通常是`/home/your_username`)下的`.bashrc`文件中添加环境变量。...

    lite.ai.toolkit与使用说明

    export LD_LIBRARY_PATH=your_path/install/third_party/onnxruntime/lib:$LD_LIBRARY_PATH ``` 注意:上述命令中的your_path需要改为第1步得到的“install”所在的父目录! ## 3. 编写Demo示例

    boa开源代码解决cgi依赖库加载失败的问题

    boa开源代码解决cgi依赖库加载失败的问题 int complete_env(request * req) ... char *env = getenv("LD_LIBRARY_PATH"); if (NULL != env) my_add_cgi_env(req, "LD_LIBRARY_PATH", env); ...... }

    pyenv-archshell:`pyenv shell` 命令的扩展,允许在必要时设置 LD_LIBRARY_PATH

    pyenv-archshell pyenv shell命令的扩展,允许在必要时设置 LD_LIBRARY_PATH。 这个插件添加了pyenv archshell命令,它是标准pyenv shell命令的包装器。 目前这个插件只对linux有影响。 如果指定了版本, archshell...

    GStreamer1.6.0一键编译安装脚本文档

    export LD_LIBRARY_PATH=$HOME/gst_1.6.0/out/lib/:$LD_LIBRARY_PATH ``` - **`WORK_DIR`** 变量记录当前的工作目录。 - **`LD_LIBRARY_PATH`** 环境变量被设置为包含自定义库路径 `$HOME/gst_1.6.0/out/lib/` 的值...

    oracle 使用命令创建oracle数据库

    1 、确定数据库的sid 和db_name  \u3000sid='hsj' ... LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH export ORACLE_BASE ORACLE_HOME ORACLE_SID PATH LD_LIBRARY_PATH  3、设置登录方法

    SAPJCO3连接配置(sapjco3-linux_x64-3.0.10)

    1.将sapjco3.jar 文件复制至 $JAVA_HOME/lib/sapjco3.jar 2.将 libsapjco3.so 文件复制至 $JAVA_...LD_LIBRARY_PATH=dir:$LD_LIBRARY_PATH:$JAVA_HOME/jre/lib/amd64/server export CLASSPATH LD_LIBRARY_PATH PATH

    06_Path环境变量的配置.avi

    java_Path环境变量的配置

    boost_1_73_0.tar.gz

    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/boost/lib export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/boost/lib export C_INCLUDE_PATH=$C_INCLUDE_PATH:/usr/local/boost/include export CPLUS_...

    HU-unix下面java调用C语言动态链接库.pdf

    LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH export LD_LIBRARY_PATH ``` 这将将当前目录添加到LD_LIBRARY_PATH环境变量中,从而使Java程序可以找到动态链接库。 五、java.library.path环境变量 java.library.path环境...

    linux 查看程序运行找不到库的问题(设置环境变量)

    解决这个问题的一个关键方法是设置或调整系统的环境变量,特别是`LD_LIBRARY_PATH`。本文将详细介绍如何在Ubuntu系统中设置环境变量来解决此类问题。 首先,我们需要理解`LD_LIBRARY_PATH`这个环境变量的作用。它是...

    gdal-2.0.1.tar.gz

    gdal-2.0.1.tar.gz安装包,大家可以根据需要下载。 1.tar -xzvf gdal-2.0.0.tar.gz 2. 编译源码。 cd gdal-2.0.0 ./configure ...添加:export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib

    Linux 手动创建Oracle数据库

    LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib export LD_LIBRARY_PATH export ORACLE_OWNER=oracle export ORACLE_SID=fzwang export ORACLE_TERM=xterm export ORA_NLS33=$ORACLE_HOME/ocommon/nls/admin/data...

    ARM-linux(fedora)随笔

    虽然使用`LD_LIBRARY_PATH`是一种快速解决问题的方法,但也有不少声音认为应尽量避免使用此变量,尤其是作为全局变量。主要原因包括: - **安全性问题**:全局设置可能导致意外加载恶意或不兼容的库。 - **维护复杂...

    解决Ubuntu下使用linuxdeployqt打包Qt程序问题

    写了点Qt界面程序,然而发现很难移植到其他没有安装Qt环境的电脑上运行。查资料了解到,在windows上有...export LD_LIBRARY_PATH=/home/xl/Qt5.9.2/5.9.2/gcc_64/lib:$LD_LIBRARY_PATH export QT_PLUGIN_PATH=/home/x

    使用LD_PRELOAD注入程序.pdf

    通常情况下,这一顺序为:LD_PRELOAD环境变量中指定的库,LD_LIBRARY_PATH指定的目录,ld.so.cache文件,系统的标准库目录/lib以及/usr/lib。通过LD_PRELOAD指定的库将优先加载,因此可以实现对程序行为的控制和修改...

    库搜索路径 库搜索路径

    export LD_LIBRARY_PATH=/path/to/library:$LD_LIBRARY_PATH ``` 这行命令会在原有值的基础上添加一个新的搜索路径。需要注意的是,这种方式只对当前用户的当前会话有效。 #### 五、配置文件/etc/ld.so.conf 管理...

    SATA硬盘仿真模型

    SATA硬盘仿真模型。The xilinx GTP is configured as SATA PHY,and 256MB DDR2 memory(Xilinx XAPP859) is HDD storge space....setenv LD_LIBRARY_PATH $LMC_HOME/lib/linux.lib:$LD_LIBRARY_PATH

Global site tag (gtag.js) - Google Analytics