FreeBSD is a secure, high performance operating system that is suitable for a variety of server roles. In this guide, we will cover some basic information about how to get started with a FreeBSD server.
Note: As of July 1, 2022, DigitalOcean no longer supports the creation of new FreeBSD Droplets through the Control Panel or API. However, you can still spin up FreeBSD Droplets using a custom image. Learn how to import a custom image to DigitalOcean by following our product documentation.
The first step you need to take to begin configuring your FreeBSD server is to log in.
To log in to your FreeBSD server, use the
ssh command. You will need to specify an existing user account along with your server’s public IP address. For the purposes of this tutorial, we’ll assume this user’s name is freebsd:
You should be automatically authenticated and logged in. You will be dropped into a command line interface.
When you are logged in, you will be presented with a very minimal command prompt that looks like this:
This is the default prompt for
tcsh, the standard command line shell in FreeBSD. In order to help us stay oriented within the filesystem as we move about, we will implement a more useful prompt by modifying our shell’s configuration file.
An example configuration file is included in our filesystem. We will copy it into our home directory so that we can modify it as we wish:
cp /usr/share/skel/dot.cshrc ~/.cshrc
After the file has been copied into our home directory, we can edit it. The
vi editor is included on the system by default. If you want a simpler editor, you can try the
The file includes some reasonable defaults, including a more functional prompt. Some areas you might want to change are the
. . . setenv EDITOR vi setenv PAGER more . . .
If you are not familiar with the
vi editor and would like an easier editing environment, you should change the
EDITOR environmental variable to something like
ee. Most users will want to change the
less instead of
more. This will allow you to scroll up and down in man pages without exiting the pager:
setenv EDITOR ee setenv PAGER less
The other item that we should add to this configuration file is a block of code that will correctly map some of our keyboard keys inside the
tcsh session. Without these lines, “Delete” and other keys will not work correctly. This information is found on this page maintained by Anne Baretta. At the bottom of the file, copy and paste these lines:
if ($term == "xterm" || $term == "vt100" \ || $term == "vt102" || $term !~ "con*") then # bind keypad keys for console, vt100, vt102, xterm bindkey "\e[1~" beginning-of-line # Home bindkey "\e[7~" beginning-of-line # Home rxvt bindkey "\e[2~" overwrite-mode # Ins bindkey "\e[3~" delete-char # Delete bindkey "\e[4~" end-of-line # End bindkey "\e[8~" end-of-line # End rxvt endif
When you are finished, save and close the file.
To make your current session reflect these changes immediately, you can source the file now:
Your prompt should immediately change to look something like this:
It might not be immediately apparent, but the “Home”, “Insert”, “Delete”, and “End” keys also work as expected now.
One thing to note at this point is that if you are using the
csh shells, you will need to execute the
rehash command whenever any changes are made that may affect the executable path. Common scenarios where this may happen are when installing or uninstalling applications.
After installing programs, you may need to type this in order for the shell to find the new application files:
The above configuration gives you a fairly good
tcsh environment. If you are more familiar with the
bash shell and would prefer to use that as your default shell, you can easily make that adjustment.
First, you need to install the
bash shell by typing:
sudo pkg install bash
After the installation is complete, we need to add a line to our
/etc/fstab file to mount the file-descriptor file system, which is needed by
bash. You can do this easily by typing:
sudo sh -c 'echo "fdesc /dev/fd fdescfs rw 0 0" >> /etc/fstab'
This will add the necessary line to the end of your
/etc/fstab file. Afterwards, we can mount the filesystem by typing:
sudo mount -a
This will mount the filesystem, allowing us to start
bash. You can do this by typing:
To change your default shell to
bash, you can type:
sudo chsh -s /usr/local/bin/bash freebsd
The next time you log in, the
bash shell will be started automatically instead of the
If you wish to change the default pager or editor in the
bash shell, you can do so in a file called
~/.bash_profile. This will not exist by default, so we will need to create it:
Inside, to change the default pager or editor, you can add your selections like this:
export PAGER=less export EDITOR=vi
You can make many more modifications if you wish. Save and close the file when you are finished.
To implement your changes immediately, source the file:
By now, you should know how to log into a FreeBSD server and how to set up a reasonable shell environment. A good next step is to complete some additional recommended steps for new FreeBSD 10.1 servers.
Afterwards, there are many different directions you can go. Some popular choices are:
Once you become familiar with FreeBSD and configure it to your needs, you will be able to take advantage of its flexibility, security, and performance.
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.
This series will show you how to get started with a FreeBSD cloud server. The first article will explain some of the differences between Linux and FreeBSD. The tutorials that follow cover the basics of FreeBSD security, maintenance, and software installation. If you are new to FreeBSD, this series will help you get up and running quickly.