Linux launches a login shell when a user logs into their account. So what are login shells and how can you tell if you are using one or not?
You can use the Linux shell every day, but how you use it largely determines how it behaves. You may have heard of the difference between a login shell and a non-login shell. And even if it doesn’t seem obvious at first, there are several differences between the two types of shells.
Here’s everything you need to know about login shells in Linux.
What is a login shell?
A login shell is exactly that: a shell that launches when you log in directly to the Linux machine. When you log into your system from a virtual console or via SSH, the shell that starts is a login shell.
On the other hand, if you start a terminal window, this shell session is usually not a login shell. The same is true when you launch a subshell by typing the shell name on the command line. This shell is just an interactive shell.
The main difference between the two is in the behavior of the shell. The shell often only reads certain files on startup. Bash will read the /etc/profilethen the .bash_profile, .bash_loginand .profile files in your home directory only if invoked as a login shell.
How to tell if you are 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 app, you probably aren’t, unless you’re in another terminal environment like WSL or macOS Terminal.
You can check if you are running a login shell with this command;
If you are using a login shell, you will see the shell name preceded by a hyphen (–). Otherwise, you will only see the shell name.
Configuring your login shell in 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:
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.
You now know about login shells
Now you should understand what login shells are. Launching your shell, either directly from the console or from a terminal window, will determine its behavior.
If you’re new to Linux, you might be wondering which shell is best. You can stick with the default Bash or explore the special features offered by alternative shells like Fish or Zsh.