简体   繁体   中英

How to run a script after user login authentication in linux

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?

For bash:

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 as all these files are executed in a loop after user logs on.因为所有这些文件在用户登录后都会循环执行。

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

For Linux Mint and Ubuntu with Desktop environment there is a option in main menu called "Startup Applications", just go there and add the path to the script file. This script will run after login in window manager.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM