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.
#chsh [options] [username]
|-s||It is used to set the login shell of a user.|
|-l||This option lists all the available shells in the 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
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
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.
To prevent user from login, assign /sbin/nologin to that user.
#chsh -s /sbin/nologin bhavana