14.6. Becoming Superuser

There are several ways to do things as the superuser. The worst way is to log in as root directly. Usually very little activity requires root so logging off and logging in as root, performing tasks, then logging off and on again as a normal user is a waste of time.

A better way is to use su(1) without providing a login but using - to inherit the root environment. Not providing a login will imply super user. For this to work the login that must be in the wheel group. An example of a typical software installation would involve the administrator unpacking the software as a normal user and then elevating their privileges for the build and installation of the software.

Example 14.11. Install a Program As The Superuser
% configure % make % su - Password: # make install # exit %

Note in this example the transition to root is less painful than logging off and back on twice.

Using su(1) works well for single systems or small networks with just one system administrator. For more complex environments (or even for these simple environments) sudo should be used. It is provided as a port, security/sudo. It allows for things like activity logging, granting users the ability to only run certain commands as the superuser, and several other options.

All FreeBSD documents are available for download at http://ftp.FreeBSD.org/pub/FreeBSD/doc/

Questions that are not answered by the documentation may be sent to <freebsd-questions@FreeBSD.org>.

Send questions about this document to <freebsd-doc@FreeBSD.org>.