在更改的用户 shell 中未读取 /etc/profile

在更改的用户 shell 中未读取 /etc/profile

我需要在用户登录系统时运行自定义二进制文件,因此我将用户的 shell 更改为 /bin/binary 到 /etc/passwd,但我观察到当我使用更改的用户 shell 登录时未读取 /etc/profile 文件

因此,只有当用户的 shell 是 /etc/passwd 中的 /bin/sh 时,才会读取 /etc/profile?

答案1

不完全的。/etc/profile如果用户的 shell 根据 /etc/passwd (或 LDAP 或其他工具)知道如何读取它并执行它,则将读取它。

如果您将 /bin/sh 替换为不知道如何读取 /etc/profile 的二进制文件,那么它将不会被读取。

修复它的一种方法显然是修复二进制文件,以便它知道如何处理 /etc/profile。

另一种方法是将用户的 shell 设置为,并在其他所有设置完成后/bin/sh编辑用户的 shell以启动二进制文件。$HOME/.profile

第三种方法是让用户使用 SSH 密钥登录,并编辑该密钥,以便它启动/bin/binary并忽略任何其他命令。您可以通过编辑用户的$HOME/.ssh/authorized_keys阅读来做到这一点,例如

 command="/bin/binary"  ssh-dss AA.....restofkeyhere....

相关内容