liunx服务器在运行自己的程序时,默认访问其他用户的文件夹路径地址,导致报错:critical libmamba filesystem error:Permission denied
liunx服务器在运行自己的程序时默认访问其他用户的文件夹路径地址导致报错。报错内容1critical libmamba filesystem error: temp directory_path: Permission denied /home/luo/Mplus]报错内容2Linux 沙箱在启动时要在这个路径下创建一个内部临时挂载目录:home/luo/Mplus/cpdex-bwrap-synthetic-mount-targets-1034但当前执行用户是rrr对/home/luo/Mplus 没有写权限所以沙箱还没开始执行 Python 命令就失败了:Permission denied (os error 13)报错内容3EACCES: permission denied, open ‘/home/luo/Mplus/kernel-v2-405528e9u64kEbvPc.json’**解决方法**取消系统级的默认写入的路径管理员全局搜索这个路径用 root 或有 sudo 的账号执行sudo grep -RIn --binary-fileswithout-match“/home/luo/Mplus|luo|Mplus”/etc/usr/local/bin/usr/local/etc/opt/usr/share/etc/skel2/dev/null重点看结果里是否来自这些位置/etc/profile/etc/bashrc/etc/bash.bashrc/etc/profile.d/.sh/etc/environment/etc/security/pam_env.conf/etc/skel/.bashrc/etc/skel/.profile/usr/local/bin//opt/*/usr/share/modules/*/etc/modulefiles/*三、重点检查全局 shell 启动文件sudo grep -RIn --binary-fileswithout-match“luo|Mplus|TMPDIR|WORKDIR|SCRATCH|MPLUS”/etc/profile/etc/bashrc/etc/bash.bashrc/etc/zshrc/etc/profile.d/etc/environment/etc/security/pam_env.conf2/dev/null如果看到类似export TMPDIR/home/luo/Mplusexport WORKDIR/home/luo/Mplusexport MPLUS_HOME/home/luo/Mplusexport PATH/home/luo/Mplus:$PATHcd /home/luo/Mplus就说明是系统级配置污染。编辑对应文件删除或修改sudo nano /etc/profile**定位到了问题就在 /etc/profile 第 93 行**/etc/profile:93:TMPDIR“/home/luo/Mplus”这说明系统级登录脚本把所有用户的临时目录 TMPDIR 都默认设置成了/home/luo/Mplus所以其他用户运行程序时很多软件会尝试往这个路径写临时文件但他们没有 luo用户目录权限于是报错。/etc/passwd、/etc/shadow 里出现 luo是正常用户信息不是问题来源。真正的问题是 /etc/profile。另外你刚才贴出了 /etc/shadow 的密码哈希信息虽然不是明文密码但仍然属于敏感信息。以后不要公开贴 /etc/shadow 输出。**1. 先查看 /etc/profile 相关片段**执行sudo nl-ba/etc/profile|sed-n80,100p你大概率会看到类似New environment setting added by Mplus …TMPDIR“/home/luo/Mplus”export TMPDIR**2. 先备份 /etc/profile**一定先备份sudo cp/etc/profile/etc/profile.bak.$(date%F_%H%M%S)确认备份成功ls-lh/etc/profile.bak.*3. 最直接的修复方式注释掉这行执行sudo sed-i s|^TMPDIR/home/luo/Mplus|# TMPDIR/home/luo/Mplus# disabled:wrong global TMPDIR|/etc/profile如果下一行还有exportTMPDIR建议先不要急着删因为它可能是别的地方也用到的。更稳妥是先查看sudo nl-ba/etc/profile|sed-n88,96p如果这个 export TMPDIR 只属于 Mplus 这段可以一起注释掉sudo sed-i s|^export TMPDIR|# export TMPDIR # disabled with wrong global TMPDIR|/etc/profile4. 更推荐的修复方式改成每个用户自己的临时目录如果你希望所有用户都有自己的临时目录可以把这一行TMPDIR/home/luo/Mplus改成export TMPDIR/tmp/${USER}mkdir-p$TMPDIR2/dev/null chmod700$TMPDIR2/dev/null可以手动编辑sudo nano/etc/profile把 Mplus 插入的这一行TMPDIR/home/luo/Mplus替换为export TMPDIR/tmp/${USER}mkdir-p$TMPDIR2/dev/null chmod700$TMPDIR2/dev/null这个方式比直接用 /tmp 更安全因为每个用户一个目录。5. 如果只是想恢复系统默认行为Linux 默认临时目录通常就是 /tmp所以也可以简单改成sudo sed-i s|^TMPDIR/home/luo/Mplus|TMPDIR/tmp|/etc/profile然后确认sudo grep-nTMPDIR\|luo\|Mplus/etc/profile如果没有特殊需求我更推荐注释掉错误的 TMPDIR 设置让系统恢复默认 /tmp 行为。6. 让当前终端立即生效对当前用户执行unset TMPDIR或者重新加载source/etc/profile但对所有用户来说最稳妥是让他们退出终端重新登录。如果是远程 SSH 用户让他们重新连接 SSH。7. 验证是否修复用普通用户执行echo$TMPDIR如果你选择注释掉正常情况下可能输出为空这没问题程序会默认使用 /tmp。再测试python-cimport tempfile; print(tempfile.gettempdir())正常应该输出类似/tmp或者如果你设置了每用户目录会输出/tmp/rrr