`
yangzb
  • 浏览: 3470028 次
  • 性别: 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工具包安装

    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...

    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_...

    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

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

    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/root/.mujoco/mujoco200/bin 报错环境 Ubunut18.04 Pycharm中 我已经在~/.bashrc中添加了环境变量 进行了source ~/.bashrc操作 在命令行中可以正确运行官网的测试demo 有...

    解决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

    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

    android-x86的glibc

    授人以渔,不如授人以鱼。拿去用吧 由于上传文件大小受限,分成了两个部分,拼好后把tools文件改名为tools.tar.bz2 ...LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/data/tools/lib gcc -o hello hello.c ./hello

    apr-iconv-1.2.1.tar.gz 、apr-util-1.5.4.tar.gz、apr-1.5.2.tar.gz

    安装tomcat-native所需模块 tar -xzvf apr-1.5.2.tar.gz cd apr-1.5.2 ./configure make & make install 接着安装apr-util和iconv,方法一样不过....export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/apr/lib

    linux下的网络调试工具

    32位linux下的网络调试...export LD_LIBRARY_PATH=$QTDIR/lib:$LD_LIBRARY_PATH, 然后打开终端运行进入解压(解压命令 tar -xjf sokit-1.3-linux32.tar.bz2 )目录 ./sokit 即可看到界面。好不容易解决的,大家珍惜

    DBD-Oracle-1.76.tar.gz

    export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH [root@rhel6 DBD-Oracle-1.76]# perl Makefile.PL [root@rhel6 DBD-Oracle-1.76]# make [root@rhel6 DBD-Oracle-1.76]# make test(可选) [root@...

    udt源码,纯C语言实现。

    export LD_LIBRARY_PATH=./src/:$LD_LIBRARY_PATH # export the library path progs/server # start the server progs/client # start the client progs/sendfile # start the sendfile server progs/recvfile ...

    Linux下安装oracle客户端-sqlplus64.zip

    安装步骤 rpm -ivh oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm rpm -ivh oracle-instantclient11.2-devel-11.2.0.4.0-1.x86_64.rpm ...export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH

    blob_demo.cpp

    资源中是深度学习caffe的数据结构blob的实例代码,通过下面的命令进行编译 g++ -o blob_demo blob_demo.cpp -...export LD_LIBRARY_PATH=/home/bigmarshal/Documents/deep_learning/caffe/build/lib/:$LD_LIBRARY_PATH

    ubantu16下的oracle12.1 client安装文件

    官网下载使用alien 转换...export LD_LIBRARY_PATH=/usr/lib/oracle/12.2/client64/lib:$LD_LIBRARY_PATH sudo mkdir -p /usr/lib/oracle/12.2/client64/lib/network/admin tnsnames.ora, sqlnet.ora or oraaccess.xml

Global site tag (gtag.js) - Google Analytics