Running a Program Right After ROOT User Logged In

Hi

I was developing an application which needs to be run like a startup app , right when the root user logged in , the program will run (so no more access to the terminal and just using the application) . I have no other users and there's just root. how can I achieve this ?

and something unrelated to this thread but related to my project , is there anyway to disable or bypass SIGSTP/SIGSTOP signals ? or is there anyway to force the program not to go to the background ? I'm using nodeJS and it can't detect or bypass this signals.


Edit:Is there anyway to run the program before user logging ?like the user login on the background and my program running above it . I want it like the user has no access to terminal (anything at all) and just working with my program
 
I was developing an application which needs to be run like a startup app , right when the root user logged in , the program will run (so no more access to the terminal and just using the application) . I have no other users and there's just root. how can I achieve this ?

Although, there is serious consequences of this, such as not being able to log in in single user mode, technically, this can be done.

Code:
~ % cat dummysh.c         
#include <stdio.h>
int main() {
char c;
while((c=getchar())!= EOF){
   putchar(c);
}
return 0;
}
~ % cc dummysh.c -o dummysh
~ % pwd                   
/home/fnoyanisi
~ % su
Password:
# chsh -s /home/fnoyanisi/dummysh test
chsh: user information updated
# exit

After changing the test user's shell, the dummysh dexecutable will be launched as soon as you log in with test user. The above code just echoes the single char you typed in and waits for the next char.
 
Hi, Omid Navy!

Edit:Is there anyway to run the program before user logging ?like the user login on the background and my program running above it . I want it like the user has no access to terminal (anything at all) and just working with my program

Make your program root's login shell, as fnoyanisi suggests. Then configure your system for auto-login:

Append :al=root: to the default entry in /etc/gettytab:

Code:
default:\
        :cb:ce:ck:lc:fd#1000:im=\r\n%s/%m (%h) (%t)\r\n\r\n:sp#1200:\
        :if=/etc/issue:al=root:

Finally, comment out all ttys in /etc/ttys except for ttyv0. This way there is only one virtual terminal, the one on which your program runs.

Best regards,
Marcel
 
such as not being able to log in in single user mode
It's generally not an issue. When you boot to single user mode the system will ask you what shell to run. So it's easy to just supply /bin/sh at that point. The supplied shell doesn't need to be the same shell as configured for the account.
 
and something unrelated to this thread but related to my project , is there anyway to disable or bypass SIGSTP/SIGSTOP signals ? or is there anyway to force the program not to go to the background ? I'm using nodeJS and it can't detect or bypass this signals.

I can't think of a way to ignore SIGSTOP, and I don't know nodeJS, but you could start your program with a wrapper that intercepts keyboard signals:

Code:
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>

int
main(int argc, char *argv[])
{
        /* Ignore signals from keyboard */
        signal(SIGINT, SIG_IGN);
        signal(SIGTSTP, SIG_IGN);
        signal(SIGQUIT, SIG_IGN);

        system("/your/program");
        /* Whatever needs to be done if this point is reached. */
        return (0);
}
 
You can't catch or ignore a SIGSTOP signal:
Code:
     17    SIGSTOP      stop process         stop (cannot be caught or ignored)
See signal(3)
 
I hadn't noticed the section, but I agree. Thread moved.
 
Make your program root's login shell, as fnoyanisi suggests. Then configure your system for auto-login:
Append :al=root: to the default entry in /etc/gettytab:

Code:
default:\
        :cb:ce:ck:lc:fd#1000:im=\r\n%s/%m (%h) (%t)\r\n\r\n:sp#1200:\
        :if=/etc/issue:al=root:

Marcel
Is there anyway to make the ssh auto login to this root account too ? (without rsa of course I mean).
 
I can't think of a way to establish this without RSA. But what's wrong with RSA?
well RSA wont suit my case , I want it exactly like the auto login which you guide me , like no user no password needing/asking and login as root user .
 
You don't need to set a password on the key. That will allow you to login without a password. You must of course protect this key vigorously as it allows anyone with access to that key a password-less root login.
 
You don't need to set a password on the key. That will allow you to login without a password. You must of course protect this key vigorously as it allows anyone with access to that key a password-less root login.

I dont need a passwordless login , i need a auto login passwordless ! i mean nothing to enter and directly logged as root! is that even possible ?
 
Back
Top