URL: https://www.pexels.com/photo/close-up-shot-of-keyboard-buttons-2882566/ By David Delony Published Aug 20, 2022, 6:00 PM EDT David is a freelance writer based in the Pacific Northwest, but originally hailing from the Bay Area. A journalist by training who has been writing professionally since 2009, he discovered the power of Unix-like operating systems and the command-line interface while learning how to edit video on macOS. It also helped that he'd originally cut his computing teeth on MS-DOS in the '90s.
He has been using Linux regularly in some form since 2006. David has been able to combine his passion for computing and writing in his career as a freelance writer. His writing has appeared in Techopedia, TMCnet, and Walyou, among others.
David holds a B.A. in communication from California State University, East Bay. A dedicated lifelong learner, he's been using Linux-based CAS tools like SymPy and Sage on Linux to make sure he remembers what he learned in his math classes and maybe even pick up a few new concepts along the way. Linux and open source have allowed him to explore advanced topics like calculus and linear algebra more easily than he could with pencil and paper. Sign in to your MakeUseOf account
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 ShellIt'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 LinuxTo 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 --login
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 ShellsYou 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.
Close