Adding Shells to the System and Making Them Available


Most users will probably be satisfied with the default FreeBSD shell, /bin/tcsh (the same as /bin/csh). It provides command-line editing, tab completion, history navigation, and the rest of the advanced shell features missing in the more rudimentary shells. However, the fact that FreeBSD defaults to tcsh rather than bash (which is commonly used in Linux) reflects the subtle philosophical differences between the BSD tradition and the System V structure (which accounts for much of the architecture of Linux), an argument as old as UNIX itself. These philosophical differences used to mean a lot more than they do today. Commercial flavors of UNIX generally fall into one camp or the other and haven't changed materially in years; between Linux and FreeBSD, though, the more significant philosophical difference is between the GNU and BSD license structures. That's where we see the roots of Linux's preference for bash and FreeBSD's preference for tcsh.

Because bash is a GNU-oriented program, and because Linux tends to prefer software developed under the GNU General Public License (GPL), bash is the default Linux shell. The feature sets of bash and tcsh are quite similar, but these features are accessed in different ways, and the configuration process and runtime behavior of the two shells differ subtly. If you are used to Linux, you may want to install bash in order to remain in a familiar environment. On the other hand, you might be a seasoned UNIX user who comes from a system in which your shell was ksh or zsh. Installing and using these shells is no problem, as you'll learn in the next section of this chapter.

Note

Bourne-style shells, of which bash is an example, are preferred by shell programmers because they're immediately compatible with any shell script you might find in the system; you can execute a shell script under bash just as easily as under sh. You can't do the same thing with C shells (csh or tcsh) because their programming syntax is very different. However, the reality of UNIX today is that shell scripts generally call their own interpreters by specifying them in their first lines (for example, #!/bin/sh), and the shell you use to execute the script is thus immaterial. That's why you'll have very few difficulties if you choose to stick with tcsh as your default shell in FreeBSD.


The remaining sections of the chapter examine both tcsh and bash, showing the differences in configuration and usage for each one. For additional shells, you're on your ownyou'll need to install the shells and read their man pages for details.

Installing Shells from the Ports or Packages

The preferred way to install software on FreeBSD is through the ports or packages, which is described in detail in Chapter 16, "Installing Additional Software." That chapter explains how to use the ports collection and the packages for all your software-management needs. This section, however, covers the most basic commands and procedures for installing new shells.

Installing from Packages

The most visual way to install a new shell is through Sysinstall and its interface to the package manager. Run sysinstall, select Configure, and then choose Packages. Select your installation mediumCD/DVD if you have the FreeBSD installation DVD handy, or FTP otherwise.

After you've received the package list, go into the shells subsection and scroll through the list of available shells. Press the spacebar to place an x on each shell you want to install. Press Tab to select the OK button and press Enter once you're done selecting shells to install, and you'll be returned to the main package selection screen. Use the right-arrow key to select Install and then press Enter. Then select OK at the confirmation screen showing the selected packages.

The software will now download automatically and install itself. Once it's done, exit out of Sysinstall by returning to the Exit option at the top of the Configuration menu; then choose Exit Install from the bottom of the screen. The shell (or shells) you've selected are now installed. You can verify that they're installed by looking in /usr/local/bin and by reading the man page for the shell you've installed (for example, man bash).

An even simpler way to install a packaged shell is straight from the command line, like this:

# pkg_add -r bash


If all goes well, just this single command should fetch and install the port from the central FreeBSD FTP server. If, however, you have a problem accessing the package repository, or the requested package is not available, you can instead compile it directly from the ports; to do this, go into the /usr/ports/shells directory, find the port directory corresponding to the shell you want to install, and then build it from downloaded source code as detailed in Chapter 16.

Note

You may need to type rehash (if you're using tcsh) to force the shell program to reread your shell configuration files and the available programs in your path after installing any new programs; otherwise, you won't be able to access those programs unless you log out and then back in.


The /etc/shells File

A very important system file that you'll need to know about when working with shells is /etc/shells. This file contains the names of the installed shells on the system, listed with their full paths. The following is an example of /etc/shells on a working system with three extra shells installed:

# cat /etc/shells # $FreeBSD: src/etc/shells,v 1.5 2000/04/27 21:58:46 ache Exp $ # # List of acceptable shells for chpass(1). # Ftpd will not allow users to connect who are not using # one of these shells. /bin/sh /bin/csh /bin/tcsh /usr/local/bin/bash /usr/local/bin/zsh /usr/local/bin/ksh


The purpose of /etc/shells is to specify the shell programs that you, the administrator, consider "valid." The chsh program (which we'll discuss shortly) won't allow a regular user to change his default shell to any program that you have not listed in /etc/shells. This safeguard allows you to ensure that a user cannot change his default shell, which executes upon login, to a program that isn't designed to be used as one. Especially problematic are setuid programs, or programs that run with the effective UID of the user that owns them (as described in Chapter 13, "Users, Groups, and Permissions"). If a setuid program is owned by root, it can execute any action with root's privileges; it's clearly not desirable for a user to be able to attain these privileges simply by logging in.

A user's shell is specified in the /etc/master.passwd user database, in the tenth field of the user's record (or the seventh field in /etc/passwd). Here's an example:

[View full width]

/etc/master.passwd: btman:*:$1$LXZkCuzD$7Oa8LyRgbjYOb.XrXiBad.:1001:1001::999066364:0: Brian Tiemann:/home /btman:/usr/local/bin/ksh /etc/passwd: btman:*:1001:1001::Brian Tiemann:/home/btman:/usr/local/bin/ksh


If that field's value (/usr/local/bin/ksh in this example) is set to a shell that appears in /etc/shells, the user is allowed to log in using services such as FTP. If not, she is denied. Also, /etc/shells is used to generate the list of available shells that you can assign to a user during the adduser process, which we cover in Chapter 13.

An entry is added automatically to /etc/shells each time you install a shell through the ports or packages, as described earlier. Note that although only the administrator (root) can change a user's shell to a program not listed in /etc/shells, a user can log in as a shell user whether or not the assigned shell appears in /etc/shells. The shells database also controls access to the system via FTP. A common trap is for an administrator to install a shell without using the ports or packages (thus not adding an entry to /etc/shells) and then to switch another user to that new shell (because the administrator is allowed to do so). The regular user can use Telnet or SSH to get to the machine without any trouble, but as soon as he tries to FTP to it, he will be inexplicably denied access. The solution to this is simply to make sure the user's shell is listed in /etc/shells. Always use the ports or packages to install shells properly; this will help you avoid such pitfalls.




FreeBSD 6 Unleashed
FreeBSD 6 Unleashed
ISBN: 0672328755
EAN: 2147483647
Year: 2006
Pages: 355
Authors: Brian Tiemann

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net