How to run a script after user login authenticatio

2020-06-04 04:41发布

问题:

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?

回答1:

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

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.



回答2:

Try adding this to your /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).



标签: linux login