This tutorial explains Linux “chsh” command, options and its usage with examples.
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.
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.
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:
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.
- Check Linux Books
- Check Information Technology Books
- Apply for Programming Internship
- Practice Programming MCQs