简体   繁体   English

如何在Linux中用户登录身份验证后运行脚本

[英]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.为此,我在/etc/rc5.d/S##rc.local文件中添加了脚本名称。 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.但后来我知道,在 rc.local 文件中添加的任何内容都会在系统启动时执行,而不是在登录身份验证之后执行。 Can anyone tell me how to run the script after user login authentication?谁能告诉我如何在用户登录身份验证后运行脚本?

For bash:对于 bash:

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,因为所有这些文件在用户登录后都会循环执行。

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).如果当前用户实际上是管理员(根据您作为管理员的标准),您将需要检查您的脚本。

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.对于具有桌面环境的 Linux Mint 和Ubuntu ,主菜单中有一个名为“启动应用程序”的选项,只需去那里添加脚本文件的路径即可。 This script will run after login in window manager.此脚本将在登录窗口管理器后运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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