没有登录/没有主目录的用户获得被拒绝的权限(redhat8)

没有登录/没有主目录的用户获得被拒绝的权限(redhat8)

我正在尝试解决一个问题。在工作中,有一个给定的任务,其中 python 应用程序当前正在服务器上运行,该应用程序正在使用一个 env 文件,其中包含用户名和密码信息。当前要求是隐藏用户名和密码字符串,使普通用户无法看到。

操作系统:redhat 8 应用程序代码库:python3

因此经过几次在线讨论后,我想出了以下方法(如果有更好、更简单的方法来解决这个问题,请随时告诉我)

应用程序由专用用户运行,比如说,nouser我计划有一个环境变量,该变量在调用运行时存储db_passwordtest_nouser.py可以访问这些值。为了进一步强化,我们可以禁用 shell 登录,以便没有用户可以以有访问权限的身份登录吗?test_nouser.pynousernouserdb_password

好的,现在我创建了一个用户

#Add user with no home dir and no shell 


sudo adduser nouser --system --no-create-home --shell=/bin/false

#determine UID


id -u nouser
986
# created new file, /etc/profile.d/nouser.sh" [New File]


cat /etc/profile.d/nouser.sh
if [ "$(id -u)" -eq 986 ]; then
    export DB_PASSWORD = 'abcd1234'
fi

# create a test python file to see if this env variable exist for nouser
cat nouser_test.py
import os

print(os.environ)

#now when I try to access these env variables, I get permission denied

su -s /bin/sh nouser 'python3 nouser_test.py'
sh: python3 nouser_test.py: Permission denied

相关内容