What Is a Login Shell in Linux?

Linux launches a login shell when a user logs in to their account. So what are login shells, and how can you find out if you’re running one or not?
You might use the Linux shell every day, but how you use it determines a lot about its behavior. You might have heard about the difference between a login shell and a non-login shell. And while it may not come off as obvious at first, there are several differences between the two shell types.
Here’s everything you need to know about login shells on Linux.
What Is a Login Shell?
A login shell is exactly that: a shell that launches when you directly log in to the Linux machine. When you log into your system from a virtual console or over SSH, the shell that starts is a login shell.
By contrast, if you start up a terminal window, that shell session is typically not a login shell. The same goes when you launch a subshell by typing the name of the shell at the command line. This shell is just an interactive shell.
The key difference between the two is in the behavior of the shell. The shell will often only read certain files on startup. Bash will read the /etc/profile, then the .bash_profile, .bash_login, and .profile files in your home directory only if it’s invoked as a login shell.
How to Tell if You’re Using a Login Shell
It’s easy to see if you’re running a login shell or not. If you launched your shell from the desktop terminal application, you most likely aren’t, unless you’re in another terminal environment like WSL or the macOS terminal.
You can check if you’re running a login shell with this command;
echo $0
If you’re using a login shell, you’ll see the name of the shell preceded by a hyphen (–). If not, you’ll just see the name of the shell.
Setting Your Login Shell on Linux
To set your login shell, use the chsh command. You can set your login shell to the absolute path of any shell listed in /etc/shells.
To start any shell as a login shell, you can usually use a command-line option. For example, to start Bash as a login shell:
bash
If you’re using a Linux desktop, you can often specify which command is run when you open a terminal window. If you want your shell to run as a login shell, you can put that option there.
Now You Know About Login Shells
You should now understand what login shells are. Launching your shell, either directly from the console or from a terminal window, will determine how it will behave.
If you’re new to Linux, you may wonder which shell is best. You can stick with the default Bash, or you can explore the special features offered by alternate shells like Fish or Zsh.