A login shell can be accessed from a text-based interface or via an SSH from remote Linux machine. However, if you log in via a graphical user interface (GUI), you can access the shell from a terminal emulator 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 anything: 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 the 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 rootadminz’s account information to view his default login shell and then change its login shell from /bin/sh to /bin/bash as follows.
# grep rootadminz /etc/passwd # usermod --shell /bin/bash rootadminz # grep rootadminz /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 rootadminz /etc/passwd # chsh --shell /bin/sh rootadminz # grep rootadminz /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 favourite command line text editors and change a specific users shell.
# vi /etc/passwd
When your done editing, save and close the file.