- How to Change Shell in Linux
- How to know the default shell?
- How to see what shell are you currently using?
- How to see all the shells available on your Linux system?
- How to change the shell to use another one?
- How to change the default shell in Linux permanently?
- 3 Ways to Change a Users Default Shell in Linux
- 1. usermod Utility
- 2. chsh Utility
- 3. Change User Shell in /etc/passwd File
- How do you change the default shell for ALL USERS to bash?
- 3 Answers 3
How to Change Shell in Linux
This quick tutorial shows how to check the running shell, available shell in the system and how to change the default shell in Linux.
This quick tutorial shows how to check the running shell, available shell in the system and how to change the default shell in Linux.
You probably are already aware that there are several shell available on Linux and other Unix-like systems. Bash is the default shell on almost all the Linux distributions but there are some other popular shells available such as:
Some of the shells provide additional features in a more user-friendly way. Take Fish shell for example. It partially starts showing you command hints based on your previous typed command. It’s quite handy if you don’t want remember the Linux terminal shortcuts all the time.
Let’s see a few things around shell in your Linux system.
How to know the default shell?
To know the default shell set for you in your Linux system, you can check the SHELL environment variable. Usually, the default shell is bash and it is shown like this:
How to see what shell are you currently using?
There is no single method that will tell you which shell you are using with 100% accuracy.
You can try either echo $0 that shows you an output like this:
or check the process using ps -p $$ like this:
ps -p $$ PID TTY TIME CMD 9625 pts/0 00:00:00 zsh
How to see all the shells available on your Linux system?
All the shells available on your Linux systems are listed in the file /etc/shells. You can use cat command or less command to view the content of the file.
# /etc/shells: valid login shells /bin/sh /bin/bash /bin/rbash /bin/dash /usr/bin/tmux /usr/bin/fish /bin/zsh /usr/bin/zsh
How to change the shell to use another one?
If you want to use a different shell, you can simply type its name and you’ll be logged into the new shell. For example, if you install zsh and want to use it, you can simply use:
You can enter exit to exit from the new shell and return to the previous one.
How to change the default shell in Linux permanently?
Suppose you liked the Fish shell a lot and you want to use it as your default shell so that every time you open the terminal or ssh into the system, you are using it instead of the default bash shell.
Linux allows you to change the default shell using the chsh command. The best way to change the default shell for your own logged in user is by specifying the shell name listed in the /etc/shells file with the -s option.
You must log out of the system so that the changes take into effect otherwise you’ll think that running chsh didn’t change the shell.
Did you notice that I had to specify the full path as it was listed in the /etc/shells file? If I had used chsh -s fish, it would have given me an error like “chsh: fish is an invalid shell”.
Which shell do you like?
Now that you know how to change shell, you may also read how to change users in Linux.
I hope this little article helped you to change the shell in Linux. If you have thought about changing the default shell, perhaps you use something other than the bash shell. Which shell is it? Why do you prefer it over the others?
Do share your views in the comments below.
3 Ways to Change a Users Default Shell in Linux
In this article, we will describe how to change a user’s shell in Linux. The shell is a program that accepts and interprets commands; there are several shells such as bash, sh, ksh, zsh, fish and many other lesser known shells available on Linux.
Bash (/bin/bash) is a popular shell on most if not all Linux systems, and it’s normally the default shell for user accounts.
There are several reasons for changing a user’s shell in Linux including the following:
- To block or disable normal user logins in Linux using a nologin shell.
- Use a shell wrapper script or program to login user commands before they are sent to a shell for execution. Here, you specify the shell wrapper as a user’s login shell.
- To meet a user’s demands (wants to use a specific shell), especially those with administrative rights.
When creating user accounts with the useradd or adduser utilities, the —shell flag can be used to specify the name of a user’s login shell other than that specified in the respective configuration files.
A login shell can be accessed from a text based interface or via a SSH from remote Linux machine. However, if you login via a graphical user interface (GUI), you can access the shell from a terminal emulators like xterm, konsole and many more.
Let’s first list all available shells on your Linux system, type.
# cat /etc/shells /bin/sh /bin/bash /sbin/nologin /bin/tcsh /bin/csh /bin/dash
Before you proceed any further, note that:
- A user can change their own shell to any thing: which, however must be listed in the /etc/shells file.
- Only root can run a shell not listed in /etc/shells file.
- If an account has a restricted login shell, then only root can change that user’s shell.
Now let’s discuss three different ways to change Linux user shell.
1. usermod Utility
usermod is a utility for modifying a user’s account details, stored in the /etc/passwd file and the -s or —shell option is used to change the user’s login shell.
In this example, we’ll first check user tecmint’s account information to view his default login shell and then change its login shell from /bin/sh to /bin/bash as follows.
# grep tecmint /etc/passwd # usermod --shell /bin/bash tecmint # grep tecmint /etc/passwd
2. chsh Utility
chsh is a command line utility for changing a login shell with the -s or –shell option like this.
# grep tecmint /etc/passwd # chsh --shell /bin/sh tecmint # grep tecmint /etc/passwd
The two methods above all modify the shell specified in /etc/passwd file which you can edit manually as in the third method below.
3. Change User Shell in /etc/passwd File
In this method, simply open the /etc/passwd file using any of your favorite command line text editors and change a specific users shell.
When your done editing, save and close the file.
Do not forget to read these related topics:
In this article, we described various ways of changing a user’s shell in Linux. To share any thoughts with us, use the comment section below.
How do you change the default shell for ALL USERS to bash?
I want every new user from now on to have bash as their shell by default. I know that to change your own shell to bash, you would use the command «chsh -s /bin/bash», but how do I automatically set all future users’ shell to bash by default?
3 Answers 3
The adduser defaults file is /etc/adduser.conf . The default shell defined by the DSHELL variable is /bin/bash by default.
Most likely you don’t need this because useradd is a very low-level utility, and it’s hardly ever used directly.
If you use useradd, edit the /etc/default/useradd skeleton file (don’t forget to make a backup though).
Set the SHELL variable to /bin/bash instead of /bin/sh .
Now every time you use useradd to add a new user bash is automatically their default shell.
Already existing users
If you want to change the shell of already existing users you have to edit the /etc/passwd file (please make sure to back have a backup of it).
Here is a description of the columns
- login name
- optional encrypted password
- numerical user ID
- numerical group ID
- user name or comment field
- user home directory
- optional user command interpreter
In that order separated by colons (:) like this.
For more information about that file consult the man page man 5 passwd .