You may use the Linux shell every day, but how you use it determines a lot about its behavior. You may have heard about the difference between a login shell and a non-login shell. And while it’s not that obvious at first glance, there are some 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 just that: a shell that starts when you log in directly to the Linux machine. When you log into your system from a virtual console or via SSH, the shell launched is a login shell.
On the other hand, when you launch a terminal window, that shell session is typically not a login shell. The same is true when you start a subshell by typing the shell’s name on the command line. This shell is just an interactive shell.
The main difference between the two lies in the behavior of the shell. The shell often only reads certain files at startup. Bash reads them /etc/profilethen the .bash_profile, .bash_loginand .profile files only in your home directory when invoked as a login shell.
How to tell if you’re using a login shell
It’s easy to tell if you’re running a login shell or not. If you started your shell from the desktop terminal application, this is most likely not the case unless you are in another terminal environment such as WSL or the macOS terminal.
You can use this command to verify that you are running a login shell;
If you are using a login shell, you will see the shell name preceded by a dash (–). If not, you only see the name of the shell.
Setting up your login shell on Linux
Use the chsh command to set your login shell. 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 the login shell:
If you’re using a Linux desktop, you can often specify what command will 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 are familiar with login shells
You should now understand what login shells are. Starting 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 might be wondering which shell is the best. You can stick with the standard bash or explore the special features offered by alternative shells like Fish or Zsh.
This article was previously published on Source link