From LQWiki
Jump to: navigation, search

chsh is a command to change your login shell.


$ chsh [-s shell] [user]

One important thing to keep in mind is that the full path to the shell must be listed in the file /etc/shells in order to be recognized as valid, so you may need to become root in order to add it. Then, under either the user or root account, issue the chsh command. (Root can change anyone's shell, but users can only change their own.)

The full path to the desired shell must be specified as in this example:

$ chsh -s /usr/local/bin/zsh

You will be asked for your password after the command, in the event you left yourself logged in and walked away from your keyboard. (Though it is unusual for *nix to protect a user from his own stupidity. rm -rf /home/user does not require a password or even a confirmation, for instance. If it's an issue for a user to be walking away from a keyboard while logged in, some might say he simply shouldn't do that or have some obtuse software 'protecting' him from it or otherwise annoying him when that is not an issue.)

After chsh finishes, you are returned to your original shell and must logout and login again (or use exec to change shells). On your next login, you will be running your new shell.

Called without arguments, chsh presents one of the following dialogs:

$ chsh
Changing the login shell for user
Enter the new value, or press return for the default
        Login Shell [/path/to/shell]: 
$ chsh
Changing shell for user.
New shell [/path/to/old/shell]:

The -l option lists the valid shells (same as cat /etc/shells). However, this and other options are not available on all chsh programs. The one written by Julianne Frances Haugh, for instance, has no 'l' option or any besides '-s' and the username.

On systems where you don't have permission to use chsh, you can place an exec command in your .profile or .login file to change your shell every time you log in. For instance, exec -c newsh -l will wipe the old shell's environment and replace it with the new shell as a login shell, which neatly circumvents all the obtuse security precautions but may not be satisfying if you wish to 'really' change your shell (i.e., the 'right' way, with it registered in /etc/passwd and so on). For that you will need to deal with whatever version of chsh you have.

Last tip - don't chsh to a restricted shell or you won't be able to change out again without root privileges.

Provided by

Most (all?) Linux distributions incorporate this from the [util-linux] project.

External links