Part I: Installing the dynamic duo, Vim and Doas
Before we configure any system components or additional software, we need a good text editor and a privilege authorisation manager. Log in with the user you configured during the installation – or root if you did not add one. You should be greeted with a console screen similar to the one below.
We’re going to install Vim and Doas to fulfil the aforementioned roles. Vim is a powerful terminal-based text editor that is available on every Unix®, BSD and GNU/Linux operating system, as well as Windows. Doas is a simple to configure alternative to the more commonly known sudo, created by the OpenBSD team, developers of another BSD operating system.
As we are logged in as our user, but Doas is not yet installed, we must gain elevated permissions to use the
pkg command to install new software packages. Enter
su -m into your terminal prompt, then enter your root password. You will be greeted by output similar to the output below.
delevingne@freebsd:~ % su -m Password: Jul 13 03:44:31 freebsd su: delevingne to root on /dev/ttyv0 root@freebsd:~ #
Now that we have root permissions, we can install Vim and Doas. To install them, enter the following into your terminal prompt and hit the enter key.
pkg install vim doas
FreeBSD will now check it’s pre-compiled binary packages for two packages: one matching the name “vim”, and another matching “doas”. You should see a long list of packages appear (108 at the time of writing). These are vim, doas, and all of the dependencies required to install them. Go ahead and enter
y in the terminal and hit enter.
All of the packages listed will now be downloaded and installed automatically. Depending on your Internet connection and your computer’s hardware, now might be a good time to get a fresh drink.
Part 2: Using Vim and Configuring Doas
Before we can move any further, you need to learn a little about how to use Vim. We will also need to configure Doas, so we can do both at the same time. The final few lines of the installation output should have told you that we need to create the
/usr/local/etc/doas.conf file, so let’s go ahead and do that now. Enter the following into your terminal.
i key on your keyboard. This will put you into Vim’s insert mode. This mode allows you to enter text into the open file. You can tell you are in insert mode as the bottom left of the terminal screen will say
-- INSERT --. Enter the following, substituting
delevingne for your username, on the first line.
permit keepenv nopass delevingne as root
This line will allow you to run commands that require root permissions whilst logged into your normal user account, if you preface the command with
doas. We’ll see that in practice shortly.
Before we can move on, we need to save the file and exit Vim. To do this, hit the
escape key. The
-- INSERT -- text should disappear from the bottom left. You are now in command mode, which is also the mode you were in when you first opened the file. If you hit the
: key, you should see a prompt appear at the bottom left. Enter
wq into this prompt and hit enter. You should see output similar to the following.
"/usr/local/etc/doas.conf" [New] 1L, 41C written root@freebsd:~ #
In the command you just entered,
w means write (also known as save) to file, and
q means quit. If you enter either command separately, as
:q, they will perform those operations separately.
Congratulations! You have successfully used Vim to configure Doas! Next up, some basic system configuration.
Sidenote: if you ever get stuck in Vim, entering
:q!will exit Vim without saving any work you have done.