While login managers have their place, they do require running X as root, and hang out in the background. For more simple setups, it be convenient to have a lighter way to startx. This is particularly true if you are running openbox or similar which does not use the features of the login manager anyway.

This method assumes a bash shell.

To begin, one could simply edit the bashrc file to start X, but this is problematic. For everyday use, X is fine, but what about when (not if) X breaks? Switching to a console and using root might be an option unless the keyboard is dead as well. Also, an SSH login should not trigger X.

We can check /proc/cmdline to see if nox was entered as the boot parameter, then check the $DISPLAY variable and finally check the SSH status.

Maybe I am misunderstanding the nohup command. As I understand it, it keeps the process running with the same priority as a foreground task while otherwise it have reduced priority and therefore run slower.

The disown is so the process is not killed by a logout on the terminal. Thanks for the link to the Arch forums. That one did not surface in my Google search.

Ottre wrote:

What about serial console logins? A more robust check would be:

Code:

if [[ $(tty) =~ /dev/tty[1-6] ]]; then

You are right! That is a much better check.

EDIT:
two more links that provide information, found vai the Arch thread:

If your X is run under user "that" and someone ctrl+alt+f1 to stop X, he will now have a console log as "that". So what ? he could have just open a new console in X and have the same.
If your X is run under a user because you don't need a login manager, how an attacker that is not "root" or "that" exist ? If you have more than one user, i suppose you would have use a login manager no ?