Gle*_*rry 13
对于所有用户,还是特定用户?对于单个用户,将其设置在他们的.bashrc文件中;对于所有用户,请查看pam_exec。
如果用户来自sshd,您需要将以下行添加到/etc/pam.d/sshd; 其他文件取决于它们的来源:
session optional pam_exec.so seteuid /path/to/my/hook.sh
Run Code Online (Sandbox Code Playgroud)
出于测试目的,该模块包含为optional,以便您在失败时仍然可以登录。确定它有效后,您可以更改optional为required. 除非你的钩子脚本执行成功,否则登录是不可能的。
注意:与往常一样,更改登录配置时,请在后台打开备份 shell,并从新终端测试登录。
还有另一种方法只影响使用 ssh 的用户而不是本地用户(在紧急情况下可能会更好)
请参阅下面 ssh 手册页中的片段。
在这种情况下,用户通常可以自己修改文件(有点像 .bashrc)
Run Code Online (Sandbox Code Playgroud)~/.ssh/rc Commands in this file are executed by ssh when the user logs in, just before the user's shell (or command) is started. See the sshd(8) manual page for more information.
这是全局的,普通用户不能修改
Run Code Online (Sandbox Code Playgroud)/etc/sshrc Commands in this file are executed by ssh when the user logs in, just before the user's shell (or command) is started. See the sshd(8) manual page for more information.