# Running a Program Right After ROOT User Logged In



## Omid Navy (Jul 12, 2017)

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


----------



## fnoyanisi (Jul 12, 2017)

Omid Navy said:


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


```
~ % 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.


----------



## mrclksr (Jul 12, 2017)

Hi, Omid Navy!



Omid Navy said:


> 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:


```
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


----------



## SirDice (Jul 12, 2017)

fnoyanisi said:


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


----------



## mrclksr (Jul 12, 2017)

Omid Navy said:


> 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:


```
#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);
}
```


----------



## SirDice (Jul 12, 2017)

You can't catch or ignore a SIGSTOP signal:

```
17    SIGSTOP      stop process         stop (cannot be caught or ignored)
```
See signal(3)


----------



## fnoyanisi (Jul 13, 2017)

By the way, this thread would fit better into Userland Programming and Scripting section.


----------



## SirDice (Jul 13, 2017)

I hadn't noticed the section, but I agree. Thread moved.


----------



## Omid Navy (Jul 15, 2017)

@mrclksr , @fnoyanisi

Thanks guys , everything works fine now.


----------



## Omid Navy (Jul 15, 2017)

mrclksr said:


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



Marcel
Is there anyway to make the ssh auto login to this root account too ? (without rsa of course I mean).


----------



## mrclksr (Jul 15, 2017)

Omid Navy said:


> 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?


----------



## Omid Navy (Jul 17, 2017)

mrclksr said:


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


----------



## SirDice (Jul 17, 2017)

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.


----------



## Omid Navy (Jul 17, 2017)

SirDice said:


> 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 ?


----------

