How to execute command before user login on linux
That's a question I've seen several time for several Linux flavours, so let's try to be exhaustive.
What is the method to execute script/command/program before and after user login into its desktop session ?
gdm lightdm lxdm
add a comment |
That's a question I've seen several time for several Linux flavours, so let's try to be exhaustive.
What is the method to execute script/command/program before and after user login into its desktop session ?
gdm lightdm lxdm
Note that in this specific use case "before login" means "after the user has logged in but before the the user's graphical environment has been initialized or before it has been presented to the user". A user's graphical environment simply does not exist at all before the user has logged in.
– AlexP
Jun 20 '18 at 11:36
@AlexP I don't get it, did I speel something wrong ? When I say before login it's before is logged in on Gnome KDE or XFCE. And you can run program before anyone indeed logged in
– Kiwy
Jun 20 '18 at 11:44
2
You can, but not in the graphical environment. The graphical environment is always per user, and a user's graphical environment does not exist before the user logs in. You can run a program in the display manager's graphical environment, because the display manager runs under a system account.
– AlexP
Jun 20 '18 at 11:49
@AlexP OK. Thanks for the precision.
– Kiwy
Jun 20 '18 at 11:52
add a comment |
That's a question I've seen several time for several Linux flavours, so let's try to be exhaustive.
What is the method to execute script/command/program before and after user login into its desktop session ?
gdm lightdm lxdm
That's a question I've seen several time for several Linux flavours, so let's try to be exhaustive.
What is the method to execute script/command/program before and after user login into its desktop session ?
gdm lightdm lxdm
gdm lightdm lxdm
edited Dec 26 '18 at 13:45
asked Jun 20 '18 at 10:39
Kiwy
5,91753556
5,91753556
Note that in this specific use case "before login" means "after the user has logged in but before the the user's graphical environment has been initialized or before it has been presented to the user". A user's graphical environment simply does not exist at all before the user has logged in.
– AlexP
Jun 20 '18 at 11:36
@AlexP I don't get it, did I speel something wrong ? When I say before login it's before is logged in on Gnome KDE or XFCE. And you can run program before anyone indeed logged in
– Kiwy
Jun 20 '18 at 11:44
2
You can, but not in the graphical environment. The graphical environment is always per user, and a user's graphical environment does not exist before the user logs in. You can run a program in the display manager's graphical environment, because the display manager runs under a system account.
– AlexP
Jun 20 '18 at 11:49
@AlexP OK. Thanks for the precision.
– Kiwy
Jun 20 '18 at 11:52
add a comment |
Note that in this specific use case "before login" means "after the user has logged in but before the the user's graphical environment has been initialized or before it has been presented to the user". A user's graphical environment simply does not exist at all before the user has logged in.
– AlexP
Jun 20 '18 at 11:36
@AlexP I don't get it, did I speel something wrong ? When I say before login it's before is logged in on Gnome KDE or XFCE. And you can run program before anyone indeed logged in
– Kiwy
Jun 20 '18 at 11:44
2
You can, but not in the graphical environment. The graphical environment is always per user, and a user's graphical environment does not exist before the user logs in. You can run a program in the display manager's graphical environment, because the display manager runs under a system account.
– AlexP
Jun 20 '18 at 11:49
@AlexP OK. Thanks for the precision.
– Kiwy
Jun 20 '18 at 11:52
Note that in this specific use case "before login" means "after the user has logged in but before the the user's graphical environment has been initialized or before it has been presented to the user". A user's graphical environment simply does not exist at all before the user has logged in.
– AlexP
Jun 20 '18 at 11:36
Note that in this specific use case "before login" means "after the user has logged in but before the the user's graphical environment has been initialized or before it has been presented to the user". A user's graphical environment simply does not exist at all before the user has logged in.
– AlexP
Jun 20 '18 at 11:36
@AlexP I don't get it, did I speel something wrong ? When I say before login it's before is logged in on Gnome KDE or XFCE. And you can run program before anyone indeed logged in
– Kiwy
Jun 20 '18 at 11:44
@AlexP I don't get it, did I speel something wrong ? When I say before login it's before is logged in on Gnome KDE or XFCE. And you can run program before anyone indeed logged in
– Kiwy
Jun 20 '18 at 11:44
2
2
You can, but not in the graphical environment. The graphical environment is always per user, and a user's graphical environment does not exist before the user logs in. You can run a program in the display manager's graphical environment, because the display manager runs under a system account.
– AlexP
Jun 20 '18 at 11:49
You can, but not in the graphical environment. The graphical environment is always per user, and a user's graphical environment does not exist before the user logs in. You can run a program in the display manager's graphical environment, because the display manager runs under a system account.
– AlexP
Jun 20 '18 at 11:49
@AlexP OK. Thanks for the precision.
– Kiwy
Jun 20 '18 at 11:52
@AlexP OK. Thanks for the precision.
– Kiwy
Jun 20 '18 at 11:52
add a comment |
1 Answer
1
active
oldest
votes
Introduction
To run a program in graphical environement before a user logged in a graphical environment depend on your display manager. A display manager is in charge to provide you a login interface and setup your graphical environment once logged in.
the most important are the following:
GDM is the GNOME display manager.
LightDM is a cross-desktop display manager, can use various front-ends written in any toolkit.
LXDM is the LXDE display manager but independent of the LXDE desktop environment.
SDDM is a modern display manager for X11 and Wayland aiming to be fast, simple and beautiful.
We will review how to setup the execution of command when the display manager popup before any user logged in and how to execute something when someone is finally logged in.
If you don't know which one you're running, you can refer to this question :
Is there a simple linux command that will tell me what my display manager is?
IMPORTANT
Before I start, you are going to edit file that except if mention execute command as root. Do not remove existing stuff in those files except if you know what you're doing and be careful in what you put in those file. This could remove your ability to log in.
GDM
Be careful with GDM, it will run all script as root, a different error code than 0 could limit your log in capability and GDM will wait for your script to finish making it irresponsive as long as your command run.
For complete explanation read the documentation.
Before Login
If you need to run commands before a user logged-in you can edit the file:/etc/gdm3/Init/Default.
This file is a shell script that will be executed before the display manager is displayed to the user.
After Login
If you need to execute things once a user has logged in but before its session has been initialize edit the file:/etc/gdm3/PostLogin/Default
If you want to execute command after the session of session initialization (env, graphical environment, login...) edit the file:/etc/gdm3/PreSession/Default
LightDM
I will talk about lightdm.conf and not about /etc/lightdm.conf.d/*.conf. You can do what you want what is important is to know the options you can use.
Be careful with lightDM, you could already have several other script starting you should read precisely your config file before editing it. also the order in which you put those script might influence the way the session load.
Before Login
LightDM works a bit differently from the others you will put options in the main configuration files to indicate script that will be execute.
Edit the main lightDM conf file:/etc/lightdm/lightdm.conf
add a line greeter-setup-script=/my/path/to/script
This script will be executed when lightDM shows the login interface.
After Login
You can edit /etc/lightdm/lightdm.conf once again and add a line:session-setup-script=/script/to/start/script
This will run the script as root after a user successfully logged in.
LXDM
Before Login
If you want to execute command before anyone logged in, you can edit the shell script:/etc/lxdm/LoginReady
After Login
If you want to execute command after someone logged in but as root, you can edit the shell script:/etc/lxdm/PreLogin
And if you want to run command as the logged in user, you can edit the script:/etc/lxdm/PostLogin
SSDM
Couldn't find proper information about that... Feel free to edit this part.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f450835%2fhow-to-execute-command-before-user-login-on-linux%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Introduction
To run a program in graphical environement before a user logged in a graphical environment depend on your display manager. A display manager is in charge to provide you a login interface and setup your graphical environment once logged in.
the most important are the following:
GDM is the GNOME display manager.
LightDM is a cross-desktop display manager, can use various front-ends written in any toolkit.
LXDM is the LXDE display manager but independent of the LXDE desktop environment.
SDDM is a modern display manager for X11 and Wayland aiming to be fast, simple and beautiful.
We will review how to setup the execution of command when the display manager popup before any user logged in and how to execute something when someone is finally logged in.
If you don't know which one you're running, you can refer to this question :
Is there a simple linux command that will tell me what my display manager is?
IMPORTANT
Before I start, you are going to edit file that except if mention execute command as root. Do not remove existing stuff in those files except if you know what you're doing and be careful in what you put in those file. This could remove your ability to log in.
GDM
Be careful with GDM, it will run all script as root, a different error code than 0 could limit your log in capability and GDM will wait for your script to finish making it irresponsive as long as your command run.
For complete explanation read the documentation.
Before Login
If you need to run commands before a user logged-in you can edit the file:/etc/gdm3/Init/Default.
This file is a shell script that will be executed before the display manager is displayed to the user.
After Login
If you need to execute things once a user has logged in but before its session has been initialize edit the file:/etc/gdm3/PostLogin/Default
If you want to execute command after the session of session initialization (env, graphical environment, login...) edit the file:/etc/gdm3/PreSession/Default
LightDM
I will talk about lightdm.conf and not about /etc/lightdm.conf.d/*.conf. You can do what you want what is important is to know the options you can use.
Be careful with lightDM, you could already have several other script starting you should read precisely your config file before editing it. also the order in which you put those script might influence the way the session load.
Before Login
LightDM works a bit differently from the others you will put options in the main configuration files to indicate script that will be execute.
Edit the main lightDM conf file:/etc/lightdm/lightdm.conf
add a line greeter-setup-script=/my/path/to/script
This script will be executed when lightDM shows the login interface.
After Login
You can edit /etc/lightdm/lightdm.conf once again and add a line:session-setup-script=/script/to/start/script
This will run the script as root after a user successfully logged in.
LXDM
Before Login
If you want to execute command before anyone logged in, you can edit the shell script:/etc/lxdm/LoginReady
After Login
If you want to execute command after someone logged in but as root, you can edit the shell script:/etc/lxdm/PreLogin
And if you want to run command as the logged in user, you can edit the script:/etc/lxdm/PostLogin
SSDM
Couldn't find proper information about that... Feel free to edit this part.
add a comment |
Introduction
To run a program in graphical environement before a user logged in a graphical environment depend on your display manager. A display manager is in charge to provide you a login interface and setup your graphical environment once logged in.
the most important are the following:
GDM is the GNOME display manager.
LightDM is a cross-desktop display manager, can use various front-ends written in any toolkit.
LXDM is the LXDE display manager but independent of the LXDE desktop environment.
SDDM is a modern display manager for X11 and Wayland aiming to be fast, simple and beautiful.
We will review how to setup the execution of command when the display manager popup before any user logged in and how to execute something when someone is finally logged in.
If you don't know which one you're running, you can refer to this question :
Is there a simple linux command that will tell me what my display manager is?
IMPORTANT
Before I start, you are going to edit file that except if mention execute command as root. Do not remove existing stuff in those files except if you know what you're doing and be careful in what you put in those file. This could remove your ability to log in.
GDM
Be careful with GDM, it will run all script as root, a different error code than 0 could limit your log in capability and GDM will wait for your script to finish making it irresponsive as long as your command run.
For complete explanation read the documentation.
Before Login
If you need to run commands before a user logged-in you can edit the file:/etc/gdm3/Init/Default.
This file is a shell script that will be executed before the display manager is displayed to the user.
After Login
If you need to execute things once a user has logged in but before its session has been initialize edit the file:/etc/gdm3/PostLogin/Default
If you want to execute command after the session of session initialization (env, graphical environment, login...) edit the file:/etc/gdm3/PreSession/Default
LightDM
I will talk about lightdm.conf and not about /etc/lightdm.conf.d/*.conf. You can do what you want what is important is to know the options you can use.
Be careful with lightDM, you could already have several other script starting you should read precisely your config file before editing it. also the order in which you put those script might influence the way the session load.
Before Login
LightDM works a bit differently from the others you will put options in the main configuration files to indicate script that will be execute.
Edit the main lightDM conf file:/etc/lightdm/lightdm.conf
add a line greeter-setup-script=/my/path/to/script
This script will be executed when lightDM shows the login interface.
After Login
You can edit /etc/lightdm/lightdm.conf once again and add a line:session-setup-script=/script/to/start/script
This will run the script as root after a user successfully logged in.
LXDM
Before Login
If you want to execute command before anyone logged in, you can edit the shell script:/etc/lxdm/LoginReady
After Login
If you want to execute command after someone logged in but as root, you can edit the shell script:/etc/lxdm/PreLogin
And if you want to run command as the logged in user, you can edit the script:/etc/lxdm/PostLogin
SSDM
Couldn't find proper information about that... Feel free to edit this part.
add a comment |
Introduction
To run a program in graphical environement before a user logged in a graphical environment depend on your display manager. A display manager is in charge to provide you a login interface and setup your graphical environment once logged in.
the most important are the following:
GDM is the GNOME display manager.
LightDM is a cross-desktop display manager, can use various front-ends written in any toolkit.
LXDM is the LXDE display manager but independent of the LXDE desktop environment.
SDDM is a modern display manager for X11 and Wayland aiming to be fast, simple and beautiful.
We will review how to setup the execution of command when the display manager popup before any user logged in and how to execute something when someone is finally logged in.
If you don't know which one you're running, you can refer to this question :
Is there a simple linux command that will tell me what my display manager is?
IMPORTANT
Before I start, you are going to edit file that except if mention execute command as root. Do not remove existing stuff in those files except if you know what you're doing and be careful in what you put in those file. This could remove your ability to log in.
GDM
Be careful with GDM, it will run all script as root, a different error code than 0 could limit your log in capability and GDM will wait for your script to finish making it irresponsive as long as your command run.
For complete explanation read the documentation.
Before Login
If you need to run commands before a user logged-in you can edit the file:/etc/gdm3/Init/Default.
This file is a shell script that will be executed before the display manager is displayed to the user.
After Login
If you need to execute things once a user has logged in but before its session has been initialize edit the file:/etc/gdm3/PostLogin/Default
If you want to execute command after the session of session initialization (env, graphical environment, login...) edit the file:/etc/gdm3/PreSession/Default
LightDM
I will talk about lightdm.conf and not about /etc/lightdm.conf.d/*.conf. You can do what you want what is important is to know the options you can use.
Be careful with lightDM, you could already have several other script starting you should read precisely your config file before editing it. also the order in which you put those script might influence the way the session load.
Before Login
LightDM works a bit differently from the others you will put options in the main configuration files to indicate script that will be execute.
Edit the main lightDM conf file:/etc/lightdm/lightdm.conf
add a line greeter-setup-script=/my/path/to/script
This script will be executed when lightDM shows the login interface.
After Login
You can edit /etc/lightdm/lightdm.conf once again and add a line:session-setup-script=/script/to/start/script
This will run the script as root after a user successfully logged in.
LXDM
Before Login
If you want to execute command before anyone logged in, you can edit the shell script:/etc/lxdm/LoginReady
After Login
If you want to execute command after someone logged in but as root, you can edit the shell script:/etc/lxdm/PreLogin
And if you want to run command as the logged in user, you can edit the script:/etc/lxdm/PostLogin
SSDM
Couldn't find proper information about that... Feel free to edit this part.
Introduction
To run a program in graphical environement before a user logged in a graphical environment depend on your display manager. A display manager is in charge to provide you a login interface and setup your graphical environment once logged in.
the most important are the following:
GDM is the GNOME display manager.
LightDM is a cross-desktop display manager, can use various front-ends written in any toolkit.
LXDM is the LXDE display manager but independent of the LXDE desktop environment.
SDDM is a modern display manager for X11 and Wayland aiming to be fast, simple and beautiful.
We will review how to setup the execution of command when the display manager popup before any user logged in and how to execute something when someone is finally logged in.
If you don't know which one you're running, you can refer to this question :
Is there a simple linux command that will tell me what my display manager is?
IMPORTANT
Before I start, you are going to edit file that except if mention execute command as root. Do not remove existing stuff in those files except if you know what you're doing and be careful in what you put in those file. This could remove your ability to log in.
GDM
Be careful with GDM, it will run all script as root, a different error code than 0 could limit your log in capability and GDM will wait for your script to finish making it irresponsive as long as your command run.
For complete explanation read the documentation.
Before Login
If you need to run commands before a user logged-in you can edit the file:/etc/gdm3/Init/Default.
This file is a shell script that will be executed before the display manager is displayed to the user.
After Login
If you need to execute things once a user has logged in but before its session has been initialize edit the file:/etc/gdm3/PostLogin/Default
If you want to execute command after the session of session initialization (env, graphical environment, login...) edit the file:/etc/gdm3/PreSession/Default
LightDM
I will talk about lightdm.conf and not about /etc/lightdm.conf.d/*.conf. You can do what you want what is important is to know the options you can use.
Be careful with lightDM, you could already have several other script starting you should read precisely your config file before editing it. also the order in which you put those script might influence the way the session load.
Before Login
LightDM works a bit differently from the others you will put options in the main configuration files to indicate script that will be execute.
Edit the main lightDM conf file:/etc/lightdm/lightdm.conf
add a line greeter-setup-script=/my/path/to/script
This script will be executed when lightDM shows the login interface.
After Login
You can edit /etc/lightdm/lightdm.conf once again and add a line:session-setup-script=/script/to/start/script
This will run the script as root after a user successfully logged in.
LXDM
Before Login
If you want to execute command before anyone logged in, you can edit the shell script:/etc/lxdm/LoginReady
After Login
If you want to execute command after someone logged in but as root, you can edit the shell script:/etc/lxdm/PreLogin
And if you want to run command as the logged in user, you can edit the script:/etc/lxdm/PostLogin
SSDM
Couldn't find proper information about that... Feel free to edit this part.
edited Jun 20 '18 at 12:44
answered Jun 20 '18 at 10:39
Kiwy
5,91753556
5,91753556
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f450835%2fhow-to-execute-command-before-user-login-on-linux%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Note that in this specific use case "before login" means "after the user has logged in but before the the user's graphical environment has been initialized or before it has been presented to the user". A user's graphical environment simply does not exist at all before the user has logged in.
– AlexP
Jun 20 '18 at 11:36
@AlexP I don't get it, did I speel something wrong ? When I say before login it's before is logged in on Gnome KDE or XFCE. And you can run program before anyone indeed logged in
– Kiwy
Jun 20 '18 at 11:44
2
You can, but not in the graphical environment. The graphical environment is always per user, and a user's graphical environment does not exist before the user logs in. You can run a program in the display manager's graphical environment, because the display manager runs under a system account.
– AlexP
Jun 20 '18 at 11:49
@AlexP OK. Thanks for the precision.
– Kiwy
Jun 20 '18 at 11:52