Archive for September, 2014

Setting Bash as the default shell in FreeBSD

Wednesday, September 24th, 2014

The default shell options on a fresh install of FreeBSD include csh, tcsh, zsh, and sh. Notably, this list does not include bash. This omission is surprising enough to most new users of FreeBSD that the FreeBSD Handbook specifically mentions it in their section on default shells.

To install bash in FreeBSD and make it the default shell, execute the following:

[root@mediaserver3 ~]# portsnap update extract
[root@mediaserver3 ~]# cd /usr/ports/shells/bash
[root@mediaserver3 ~]# make install clean

This may take 10 to 15 minutes to install and compile and there will likely be several prompts regarding additional patches, options, etc. throughout the installation that you will need to answer. Stick with the default options and you’ll be fine.

Once bash finishes compiling and installing, you can set it as the default shell for any user by using the chsh command:

[root@mediaserver3 ~]# chsh -s /usr/local/bin/bash mediaserver3
[root@mediaserver3 ~]# chsh -s bash mediaserver3

To confirm that the shell for that particular user was changed, finger them:

[root@mediaserver3 ~]# finger mediaserver3

Note: The FreeBSD Handbook specifically warns against changing the default shell for root “since shells which are not included in the base distribution are installed to /usr/local/bin. In the event of a problem, the file system where /usr/local/bin is located may not be mounted. In this case, root would not have access to its default shell, preventing root from logging in and fixing the problem.”

I’ll leave the choice of ignoring this warning up to you. For the record, I went ahead and enabled bash as root’s default shell. I reasoned that should I somehow manage to so fundamentally break the system that I’m not even able to log in as root anymore (unlikely), then it’s still trivially easy to boot from the FreeBSD Live CD, mount the drive, and switch root’s shell back to tcsh or fix anything else that’s broken. Your call.