Bash manual says:

A login shell is one whose first character of argument zero is‘ -’, or one invoked with the --login option.

It defines a login shell in terms of the ways to start a login shell.

Alternatively, can a login shell be defined in terms of its intended purpose?

For example, can a login shell be defined as a shell which requires user to log in? For example, in an interactive nonlogin bash shell, when I run bash --login to create a bash login shell, I don't have to log in. Is it because my username and password are cached and reused implicitly, or simply it doesn't perform the job of login?

If a login shell doesn't necessarily have to perform log in, what is its intended purpose that can characterize a login shell from a nonlogin shell?


2 Answers 2


Login is handled by tools other than the shell, e.g. login itself, or your desktop manager (with the help of PAM and various other tools).

The purpose of a login shell isn’t to handle login, it’s to behave appropriately as the first shell in a login session: mainly, that means processing startup files which should only be processed once per login session, and protecting the login session from unwanted interaction with certain system features (job suspension in particular).

The specifics of a login shell, at least as implemented in Bash, are as follows:

  • a login shell processes commands from /etc/profile, then the first file it finds among ~/.bash_profile, ~/.bash_login, and ~/.profile (unless it’s a non-interactive login shell started without the --login option);
  • exiting a login shell runs logout instead of exit;
  • exiting a login shell hangs up all jobs;
  • a login shell can’t be suspended;
  • a login shell sets the HOME variable (except in POSIXly-correct mode);
  • a login shell sets the login_shell shell option.
  • Thanks. 1. The first bullet point only applies to login shells which are started with --login option. Remember BASH_ENV? 2. I was wondering where I can also find "the specifics of a login shell"? I don't find it in the bash manual.
    – Tim
    Commented Apr 6, 2018 at 12:48
  • 2
    1. No, it applies to all interactive login shells. Are you still talking about non-interactive login shells? 2. I read the Bash source code. Commented Apr 6, 2018 at 12:54
  • 1. right. I was more focused on login shells vs nonlogin shells. So was trying to see the intended purpose of login shells, which might be interactive or not. 2. Do you have a link? It is nice to have one, although I am yet able to understand.
    – Tim
    Commented Apr 6, 2018 at 12:57
  • You’ll find the source code here; look for login_shell to find all the login-shell-specific handling. Commented Apr 6, 2018 at 13:12
  • Thanks. "a login shell processes commands from /etc/profile, then the first file it finds among ~/.bash_profile, ~/.bash_login, and ~/.profile". If I am correct, a noninteractive login shell not started with --login option doesn't read and execute " ~/.bash_profile, ~/.bash_login, and ~/.profile".
    – Tim
    Commented Apr 6, 2018 at 16:31

You already answer yourself your question.

when I run bash --login to create a bash login shell, I don't have to log in

It means that you are already logged in and already have an environment that allows you to start application with your user rights.
Happily you don't have to type your password each time you start an application once you logged in.
The main difference is that with option -l or --login :

[bash] first attempts to read and execute commands from /etc/profile and ~/.profile, in that order.

(extract from man bash).

The purpose would be to benefit from /etc/profile and ~/.profile. bash is a shell, not the component that handles a user session. PAM is the linux component that is responsible to identify you with your login/password.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .