Updated: October 29, 2021

A brief introduction to some of the commands and functionality of the FreeBSD operating system. This guide will cover the commands that a new user will need to initially start working with FreeBSD as well as how to use the FreeBSD manual pages for more information.

1. Configuring and Using Video Modes

1.1 Virtual Consoles

FreeBSD is configured to log users into the system console, this is identified as (ttyv0). System messages will be displayed in this console by default, occasionally causing issues if the user is entering commands.

FreeBSD also supports multiple virtual consoles to help with this problem. By default these consoles can be accessed by a combination of the alt and F-keys. For example, alt+F2 will open the first virtual console, alt+F3 will open the second, and so on. To re-access the system console use alt+F1.

Virtual Consoles can be used to create the feeling of having multiple screens that can be used. In addition, commands that have been entered on one console will continue to run even when the user switches to a different console.

1.2 Changing Video Modes

The FreeBSD video mode is extremely versatile and easy to configure. The video mode can be adjusted to any size supported by the graphics card.

To configure the video mode, first load the VESA module:

$ kldload vesa

Next, you’ll need to determine which video modes are supported. The vidcontrol command can be used to output a list of available modes:

$ vidcontrol -i mode

The list of supported modes will number the video modes as well as containing a brief description of the video mode. To switch the video mode, specify the number of the mode you would like to use, the following is an example for switching to mode 279:

$ vidcontrol MODE_279

1.3 Further Video Configuration

The vidcontrol command used in the last section is an extremely powerful system utility and can be further used to configure the system and virtual consoles.

Navigate to the vidcontrol manual page. Manual pages contain information on commands, as well as instructions for proper use. For example, in the last section we used the vidcontrol command but applied the “-i mode” option. This told the system to list possible video modes that are supported.

Play with the vidcontrol command a bit until you are comfortable with applying parameters to commands. To start off, try to enable the mouse pointer on the console:

$ vidcontrol -m  on

The first part of the code is the command, in this case vidcontrol, followed by the command option “-m” instructing the system that the user is applying a change to the mouse pointer. In this case, the -m option has two possible arguments “on” and “off”. Play around further with the command and see if you can change the text color and background.

2. User/Account Management:

2.1 The Superuser Account

Some commands will require superuser, often referred to as “root”, privileges in order to execute. The superuser account has no limitations so it is not recommended to use the account for common commands as a typo or mistake could destroy the operating system. To avoid this, you should only access the superuser account when executing commands that require extra privileges. 

While a user could log into the root account on startup, the recommended method is to use the sucommand to access the root account. In order to run this command the user must be in the wheel group. After entering the command, the system will prompt the user to enter the root password:

$ su

Once the user is done with the command, the superuser session can be ended by using the exit command:

$ exit

2.2 Managing User Accounts

A variety of user utilities are included in the FreeBSD operating system. The primary ones will be covered in this section.

$ adduser

The adduser command starts an interactive user-setup that you may recognize from the initial installation of FreeBSD. It is the recommended tool for setting up new accounts because it creates a home directory for the new user.

$ rmuser jru

The rmuser command is the recommended tool for removing accounts and cleaning up the processes and directories associated with the user. The example above is removing the user “jru”.

$ passwd jru

The passwd command can be used to change and set a new password for accounts. 

$ pw groupmod wheel -m jru

The pw command is an extremely powerful user group utility. In this example, we are using it to add “jru” to the wheel group. It is recommended to read the manual page for this command as it is quite a bit more complicated than the other commands in this section.

3. Editing Text Files:

3.1 Basic Text Editor

FreeBSD comes with a simple, yet limited, text editor “ee“, or easy editor. This utility opens an editor display and lists the available commands at the top. The following example is how a user would edit the rc.conf file with easy editor:

$ ee /etc/rc.conf

Once the command has been executed, the display opens and allows you to make changes to the chosen file. The “^” symbol used in the command represents Ctrl and the utility can be quit using the Esc key.

While easy editor is a great utility for a new user, many more experienced users will find the utility to be limited and time-consuming to use.

3.2 Advanced Text Editor

Another text editor that FreeBSD includes is the extremely versatile vi command. Executing the command starts a text-based editor that allows users to directly view and edit text files. The vi editing options are not listed in the same way as the ee commands, however, more experienced users will find that once they become more experienced with vi, text editing becomes much easier and less time-consuming. Much like the last section, to edit the rc.conf text file using the vi command:

$ vi /etc/rc.conf

Arrow keys can be used to navigate the text file. The editing options can be found listed on the command’s manual page if you scroll down to the second section. These commands can be entered by first hitting the Esc key, followed by the command.

For example, if a user is trying to add text directly after the cursor the user would first hit the Esc key to exit the previous command, then hit the a key. They would then be able to enter the text they wish to add. 

Because the sheer number of text-editing options, users should read through the manual page before using the vi command.

4. System Startup

For FreeBSD, at system boot, /etc/rc reads /etc/rc.conf and /etc/defaults/rc.conf to determine which services are to be started. The specified services are then started by running the corresponding service initialization scripts located in /etc/rc.d/ and /usr/local/etc/rc.d/.

The scripts found in /etc/rc.d/ are for applications that are part of the “base” system, such as cron(8)sshd(8), and syslog(3). The scripts in /usr/local/etc/rc.d/ are for user-installed applications such as Apache and Squid.

User-installed applications are not considered to be part of the “base” system and are generally installed using Packages or Ports. In order to keep them separate from the base system, user-installed applications are installed under /usr/local/. Therefore, user-installed binaries reside in /usr/local/bin/ and configuration files are in /usr/local/etc/.

Services are enabled by adding an entry for the service in /etc/rc.conf. The system defaults are found in /etc/defaults/rc.conf and these default settings are overridden by settings in /etc/rc.conf. Refer to rc.conf(5) for more information about the available entries. When installing additional applications, review the application’s install message to determine how to enable any associated services.

The following entries in /etc/rc.conf enable sshd(8), enable Apache 2.4, and specify that Apache should be started with SSL:

$ enable SSHD
sshd_enable="YES"
$ enable Apache with SSL
apache24_enable="YES"
apache24_flags="-DSSL"

Once a service has been enabled in /etc/rc.conf, it can be started without rebooting the system:

# service sshd start
# service apache24 start

If a service has not been enabled, it can be started from the command line using onestart:

$ service sshd onestart

5. Manual Pages

The most comprehensive documentation on FreeBSD is in the form of manual pages. Nearly every program on the system comes with a short reference manual explaining the basic operation and available arguments. These manuals can be viewed using man:

$ man command

where command is the name of the command to learn about. For example, to learn more about ls(1), type:

$ man ls

Manual pages are divided into sections which represent the type of topic. In FreeBSD, the following sections are available:

  1. User commands.
  2. System calls and error numbers.
  3. Functions in the C libraries.
  4. Device drivers.
  5. File formats.
  6. Games and other diversions.
  7. Miscellaneous information.
  8. System maintenance and operation commands.
  9. System kernel interfaces.

In some cases, the same topic may appear in more than one section of the online manual. For example, there is a chmod user command and a chmod() system call. To tell man(1) which section to display, specify the section number:

$ man 1 chmod

This will display the manual page for the user command chmod(1). References to a particular section of the online manual are traditionally placed in parenthesis in written documentation, so chmod(1) refers to the user command and chmod(2) refers to the system call.

If the name of the manual page is unknown, use man -k to search for keywords in the manual page descriptions:

$ man -k mail

This command displays a list of commands that have the keyword “mail” in their descriptions. This is equivalent to using apropos(1).

To read the descriptions for all of the commands in /usr/sbin, type:

$ cd /usr/sbin
$ man -f * | more