When to Use login and non-login shells in Linux

This blog post will discuss the differences between login and non-login shells and provide guidance on when to use each type of shell.

Login VS non-login shells

  • Startup is configured differently for login and non-login shells
  • Login shells are:
    • Any shell created at login (includes X login)
    • su –
  • Non-login shells are: –
    • su
    • graphical terminals
    • executed srpts
    • any other bash instances

Most of the configuration items that we have seen in this unit are only valid in the given shell. But typically, we will want settings to be established every time we start a shell, rather than having to type in all of our variables, aliases, and other commands on a per shell basis.

To accomplish this, we use startup scripts, scripts that run when a shell is created. The system administrator sets up some startup scripts, but individual users can control startup by editing scripts in their home directories.

A critical concept to understand when it comes to startup scripts is the idea of the login shell. A login shell is a shell that someone started by logging into the system. A non-login shell is a shell started up in some other way, perhaps by a user or a program issuing the bash command.

The login shell is an important concept because different startup scripts run, depending on whether a shell is a login shell or a non-login shell.

Leave a Comment