如何在Linux中用户登录身份验证后运行脚本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10797150/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to run a script after user login authentication in linux
提问by user976754
I have a script which I want to run just after user log-in authentication. To accomplish this, I added the script name in /etc/rc5.d/S##rc.local
file. But later i got to know that, anything that is added in rc.local file gets executed in boot time of the system not after the login authentication. Can anyone tell me how to run the script after user login authentication?
我有一个脚本,我想在用户登录身份验证后立即运行。为了实现这一点,我在/etc/rc5.d/S##rc.local
文件中添加了脚本名称。但后来我知道,在 rc.local 文件中添加的任何内容都会在系统启动时执行,而不是在登录身份验证之后执行。谁能告诉我如何在用户登录身份验证后运行脚本?
回答by lanzz
Try adding this to your /etc/pam.d/login
:
尝试将此添加到您的/etc/pam.d/login
:
session optional pam_exec.so /bin/bash /path/to/your/script.sh
You will need to check in your script if the current user is actually an administrator (according to whatever your criteria for being administrator are).
如果当前用户实际上是管理员(根据您作为管理员的标准),您将需要检查您的脚本。