Linux chsh command

chsh command is used to change the login shell of a user. A root user can change login shell of any user whereas a normal user can change its own login shell.

Syntax of Linux chsh command

#chsh [options] [username]

Command line options of Linux chsh command

Options Description
-s It is used to set the login shell of a user.
-l This option lists all the available shells in the system.

How to display a list of available shells in Linux system?

To get a list of all shells that are available in your Linux system, run cat /etc/shells or chsh -l command.

#chsh -l
/bin/sh
/bin/bash
/bin/csh
/bin/tcsh
/bin/zsh
/sbin/nologin
#cat /etc/shells
/bin/sh
/bin/bash
/bin/csh
/bin/tcsh
/bin/zsh
/sbin/nologin

How to change own's login shell?

Suppose raghav is currently logged-in in the system, and he want to change his shell to /bin/tcsh then run the below command-

#echo $SHELL
/bin/bash
#chsh -s /bin/tcsh
#echo $SHELL
/bin/tcsh

Now, you can see above that login shell of user raghav is changed to /bin/tcsh

How to change login shell for any user?

Run the below command to change shell of a user, but it must be run by root user. Suppose, we want to change the shell of user madhav to /bin/sh.

#chsh -s /bin/sh madhav
Changing shell for madhav.
Shell changed.

How to prevent user from login?

To prevent user from login, assign /sbin/nologin to that user.

#chsh -s /sbin/nologin bhavana