chsh Command Examples in Linux

This tutorial explains Linux “chsh” command, options and its usage with examples.

“chsh” command is used to change login shell. This post describes “chsh” command used in Linux along with usage examples and/or output.

Usage:
chsh [options] [LOGIN]

The “chsh” command changes the user login shell. This determines the name of the user’s initial login command. A normal user may only change the login shell for her own account; the superuser may change the login shell for any account. chsh is a setuid program.

Here’s the listing of example usage of chsh command. :

1. To print the list of available shell in the system(chah -l):
The -l option displays the list of shells listed in /etc/shells file or simply you can cat the file.

sanfoundry-> cat /etc/shells 
# /etc/shells: valid login shells
/bin/csh
/bin/sh
/usr/bin/es
/usr/bin/ksh
/bin/ksh
/usr/bin/rc
/usr/bin/tcsh
/bin/tcsh
/usr/bin/esh
/bin/dash
/bin/bash
/bin/rbash

In Linux for listing the names of the shells you may use ” chsh –list-shells also.

advertisement
advertisement

2. To change the login shell (chsh):

sanfoundry-> chsh 
Password: .......
Changing the login shell for user_name
Enter the new value, or press ENTER for the default
Login Shell [/bin/bash]: /bin/dash
sanfoundry->

If you mistype the name of the shell or specify a shell that is not available on your system, you will get a error message.

Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

3. To change my current login shell from bash to ksh(chsh -s path_to_ksh):

sanfoundry-> echo $SHELL
/bin/bash
sanfoundry->chsh -s /bin/ksh
sanfoundry-> echo $SHELL
/bin/ksh

“echo $SHELL” command shows the the current shell which you are using.
Here ksh is the Korn shell.

4. To change shell for other user:

advertisement
root@sanfoundry->chsh -s /bin/csh xyz
Changing shell for xyz.
Shell changed.

The example above show, the “chsh” command is issue by the root operator to change shell for another user in this case is for user xyz.

NOTE
The only restriction placed on the login shell is that the command name must be listed in /etc/shells, unless the invoker is the superuser, and then any value may be added. An account with a restricted login shell may not change her login shell. For this reason, placing /bin/rsh in /etc/shells is discouraged since accidentally changing to a restricted shell would prevent the user from ever changing her login shell back to its original value.

Sanfoundry Global Education & Learning Series – 1000 Linux Tutorials.

advertisement
If you wish to look at all Linux commands and their usage examples, go to Linux Commands Tutorial.

If you find any mistake above, kindly email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.