用户登录后,消息可以通过哪些不同的方式显示到 bash shell?

Wes*_*ley 16 linux bash login ssh centos

我有一个使用 bash 作为外壳的 CentOS 5.7 VPS,它在通过 SSH 登录后立即显示品牌问候语。我一直在尝试修改它,但似乎无法在通常的地方找到它的位置。到目前为止,我已经查看了motd文件并检查sshd_config了横幅文件设置。未设置横幅文件。

我还可以在哪里查找登录消息的位置?

Gil*_*il' 22

传统的 Unix 系统会/etc/motd在用户成功通过身份验证之后和调用用户的 shell 之前显示。在现代系统上,这是由pam_motdPAM 模块完成的,它可以配置在不同的文件中/etc/pam.conf/etc/pam.d/*显示不同的文件。

SSH服务器本身可以被配置为打印/etc/motd,如果PrintMotd在选项未关闭/etc/sshd_config。如果PrintLastLog没有关闭,它还可以打印上次登录的时间。

另一个传统消息可能会告诉您是该消息You have new mail还是You have mail. 在带有 PAM 的系统上,这是由pam_mail模块完成的。某些 shell 可能会打印有关可用邮件的消息。

用户的 shell 启动后,用户的启动文件可能会打印额外的消息。对于交互式登录,如果用户的登录 shell 是 Bourne 样式的 shell,请在/etc/profile~/.profile、 plus~/.bash_profile~/.bash_loginbash 中查找。对于交互式登录zsh的,看在/etc/zprofile/etc/zlogin/etc/zshrc~/.zprofile~/.zlogin~/.zshrc。对于 csh 的交互式登录,请查看/etc/csh.login~/.login

如果用户的登录 shell 是 bash 并且这是一个非交互式登录,那么 bash 就会执行~/.bashrc(这真的很奇怪,因为~/.bashrc只有当 shell 不是登录 shell 时才会为交互式 shell 执行)。这可能是麻烦的根源;~/.bashrc如果 shell 不是交互式的,我建议在顶部包含以下代码片段:

if [[ $- != *i* ]]; then return; fi
Run Code Online (Sandbox Code Playgroud)


Kar*_*son 8

有几个:

/etc/motd
/etc/issue
/etc/profile - Could echo the message
/etc/profile.d/* - Would be called from /etc/profile
Run Code Online (Sandbox Code Playgroud)

此外

/etc/bash_bashrc
/etc/.bashrc
/etc/bashrc
$HOME/.profile
$HOME/.bashrc
Run Code Online (Sandbox Code Playgroud)

您可能还必须检查从这些脚本中调用的每个程序,因为类似的东西fortune可能会存储它在/usr/share. 要隔离它,您可以执行以下操作:

. /etc/profile
. /etc/bash.bashrc
. $HOME/.profile
. $HOME/.bashrc
Run Code Online (Sandbox Code Playgroud)

在 Ubuntu 上还有文件:

/etc/motd.tail
Run Code Online (Sandbox Code Playgroud)