Changing your login shell

Posted by Steve on Mon 29 Aug 2005 at 16:00

If you wish to experiment with a new shell the most natural way to do it is to change your login shell. There are two ways to do this, the right way and the wrong way.

When you login to a system you will be given your login shell, as taken from the last field in the /etc/passwd file.

For example in the following snippet we see entries for two users, skx and steve:

skx:x:1000:1000:Steve Kemp,,,:/home/skx:/bin/bash
steve:x:1002:1000:Steve Kemp,,,:/home/steve:/bin/zsh

The first user, skx, has his login shell set to /bin/bash. The second user has his shell set to /bin/zsh.

To change a login shell you might be tempted to directly edit the /etc/passwd file manually - this is the wrong thing to do. (And not possible if you don't have root permissions anyway!)

Old-timers will be appalled at people changing shells by editing the password file manually, much like they do when people talk about changing root's shell - but that's another story.

The correct way for a user to change his or her shell is via the chsh command.

chsh stands for change shell, and does exactly what the name suggests.

Invoke it with no arguments and you will be prompted for your password, then you will be prompted for your shell.

The file /etc/shells is consulted, and your chosen shell must be included in there for your change to be accepted. If you enter the name of a binary which is not contained in /etc/shells you'll receive and error similar to this:

skx@mystery:~$ chsh
Password: 
Changing the login shell for skx
Enter the new value, or press return for the default
        Login Shell [/bin/sh]: /bin/fff
/bin/fff is an invalid shell.

(All Debian shell packages should insert the name of their binary into the shells file; if they do not this is a bug).

If you're root you can change the shell for a user by adding the username to the command line:

root@mystery:~# chsh skx

You can also supply the shell name without being prompted for it interactively with the -s argument:

root@mystery:~# chsh -s /bin/zsh skx

Or:

skx@mystery:~$ chsh  -s /bin/bash 
Password: 

This article can be found online at the Debian Administration website at the following bookmarkable URL:

This article is copyright 2005 Steve - please ask for permission to republish or translate.