This site is now 100% read-only, and retired.

Changing your login shell

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

Tags:

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: 

 

 


Re: Changing your login shell
Posted by Anonymous (85.65.xx.xx) on Mon 29 Aug 2005 at 20:54
Is editing the passwd file the wrong way because there is a better way (chsh) or because it might cause unforseen trouble?

[ Parent ]

Re: Changing your login shell
Posted by Steve (82.41.xx.xx) on Mon 29 Aug 2005 at 21:01
[ 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 ]

Re: Changing your login shell
Posted by Anonymous (81.65.xx.xx) on Mon 29 Aug 2005 at 21:08
It's the wrong way because you need to use root to do so.
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 ]

Re: Changing your login shell
Posted by Anonymous (66.179.xx.xx) on Mon 29 Aug 2005 at 21:55
Unforseen trouble. Also, portability: chsh should work whether your user database is /etc/passwd, NIS, an LDAP server, or whatever.

[ Parent ]

Re: Changing your login shell
Posted by Anonymous (81.178.xx.xx) on Sun 4 Sep 2005 at 16:39
The real problem is concurrency. This is a real multi user operating system, so multiple people might be trying to change their shell, their password, or whatever, all at once. chsh, vipw, passwd, and other tools like them are designed to first lock the passwd backend so as to prevent corruption from multiple update attempts at the same time. To see how effective they are, try to run 2 instances of vipw from different terminals.

[ Parent ]

Re: Changing your login shell
Posted by hardik (61.95.xx.xx) on Tue 30 Aug 2005 at 05:50
My user database is in LDAP, What about that, It doesn't support it. It should support...... With Cheers, Hardik Dalwadi.

[ Parent ]

Re: Changing your login shell
Posted by Anonymous (64.142.xx.xx) on Tue 30 Aug 2005 at 15:55
I unfortunately developed the habit of changing my shell with vipw from solaris days when there was no bash shell in /etc/shells across the network of NFS machines, so I would set my shell to some /nfs/something/bash which chsh would reject. vipw rejeted nothing!

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 ]

Re: Changing your login shell
Posted by gonad (219.89.xx.xx) on Thu 1 Sep 2005 at 07:37
pflogsumm is an awesome one for Postfix.

[ Parent ]