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:
[ Parent | Reply to this comment ]
[ Send Message | View Steve's Scratchpad | View Weblogs ]
Both.
It is mostly so that you don't end up with a damaged password file, or setup an invalid path to your shell.
(ie. The same rationale for using visudo over "$editor /etc/sudoers" applies here.)
Steve
-- Steve.org.uk
[ Parent | Reply to this comment ]
By the way editing passwd, groups & shadow manually is a bad idea in case of typo. adduser, chsh & co. are the best way as they won't corrupt theses core files.
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
Sure I couldn't log in if NFS was down, but the whole user interface would generally lock up on every computer when NFS was down anyway.
Nowadays, of course, I've almost forgotten about these commands, since bash works dandily by default.
--JoshuaRodman
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]