如何在linux中进行用户登录验证后运行脚本

时间:2021-11-01 04:51:46

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文件中添加的任何东西都会在系统的引导时间内执行,而不是在登录验证之后执行。任何人都可以告诉我如何在用户登录身份验证后运行脚本?

2 个解决方案

#1


12  

Alternatively, you can add your script to /etc/profile.d folder.

或者,您可以将脚本添加到/etc/profile.d文件夹。

More reading about this here and here.

更多关于这里和这里的阅读。

Basically, you should give your script the extension .sh as all these files are executed in a loop after user logs on.

基本上,您应该为脚本提供扩展名.sh,因为所有这些文件都是在用户登录后在循环中执行的。

#2


3  

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).

如果当前用户实际上是管理员(根据您作为管理员的标准,则需要签入脚本)。

#1


12  

Alternatively, you can add your script to /etc/profile.d folder.

或者,您可以将脚本添加到/etc/profile.d文件夹。

More reading about this here and here.

更多关于这里和这里的阅读。

Basically, you should give your script the extension .sh as all these files are executed in a loop after user logs on.

基本上,您应该为脚本提供扩展名.sh,因为所有这些文件都是在用户登录后在循环中执行的。

#2


3  

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).

如果当前用户实际上是管理员(根据您作为管理员的标准,则需要签入脚本)。