Moving away from Ubuntu: peeking at FreeBSD (Part 1)
Tags: unix, experimenting, freebsd, shell
Published: 2019-12-22 18:50:05

I've been aware of the existence of OSes besides Windows since I was given my small green laptop by my school, as a result of some politicians in my region attempting to get a nice picture taken, and it showed: the computer was a low-end one, even for the day's standards (we're talking about 2010 or so), so there wasn't a lot that you could do on it comfortably. For example, after a few years, I wasn't able to properly browse any web sites, and let's not talk about the fact I couldn't run an IDE on it when I had to bring it to classes in order to code on it: it crashed spectacularly or simply refused to run at all.

Even though, I'm glad of having had it: **it made me deal with some form of Ubuntu for the first time**, as my parents wouldn't let me use their *better*, but still sorta low-end, Windows machine, ~~they didn't want me to download things on it and eventually make it unable to boot~~, so I had to spend time learning how things worked on there. Not that much of a problem for me, but it was a deal-breaker for most of my classmates.

Regardless, nowadays, I have *some* culture about how Linux came to be and their relatives and, as I don't really need Windows, ~~since the games I want to play are available on Linux or are playable in Wine or even a VM~~, and I'm pretty much aware of how painful it can be when it's cracked, I just prefer to use Ubuntu in my main computer. Besides, it's very likely I'll end up working with a Linux machine, and that way it won't be that big of a deal for me, especially when it comes to running commands.

However, to be honest, I have never used any distro other than Debian-based ones (with different desktops) for a reasonable amount of time, and I've always been curious about how different it is to work on other distributions. Sure, a lot of things will be very similar, but I still want to see **how different** it really is by myself.

So, I'm going to start by shooting at the dark with the first one: **FreeBSD**

# What's FreeBSD?

![FreeBSD logo](https://thepracticaldev.s3.amazonaws.com/i/p8jyvxodxkows5fgsnp4.png)

**FreeBSD isn't really a Linux distribution,** but an OS derived from one of its relatives, BSD. This operating system was created by the University of California, Berkeley from Unix's source code and, soon before its original development ceased, became the basis of several open-source OSes under the BSD license, including FreeBSD, which allowed the code to be used in proprietary projects such as Apple's OSes and PS3 and PS4's OSes.

Obviously, by itself, it's much less popular and, according to some posts out there, harder to use than Linux, especially in desktop, even though it's somewhat better when it comes to running servers. **There's no way I can reliably measure its performance in a server,** but I should be able to tell if it's a lot more of a pain to use than Ubuntu Server.

# My goals

In order to give FreeBSD a first try, I'm going to attempt to do the following tasks after installing it:

0. Figuring out the folder structure (if it's any different from [FHS](https://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard))

1. Installing an SSH server in order to use it from a terminal

2. Trying to install a web server (Apache is preferred), make it work with PHP and run a script to read some data from a local database.

3. Attempting to install a desktop environment

# The setup

In order to keep it simple, I'm going to create a VM using VirtualBox with 2GB of RAM and a 30GB virtual HDD. I'm choosing the defaults for FreeBSD, so the storage layout comes out like this:

![Storage setup](https://thepracticaldev.s3.amazonaws.com/i/ybghf8bn29mbbk4tjio9.png)

For the network, I simply change the default network adapter to be attached to a bridged adapter, which will make the VM fully visible for my local network:

![Network setup](https://thepracticaldev.s3.amazonaws.com/i/w913eoze1i5gmrh244pf.png)

# Installation

I boot up the virtual machine after selecting the FreeBSD installation image for the virtual disc drive. I'm greeted by this screen upon waiting for a countdown to run out.

![First screen](https://thepracticaldev.s3.amazonaws.com/i/bgjac9smv2zj92q0zrex.png)

I select the Install option and arrive at the keymap screen. Since I don't have a standard US keyboard, I first try the "Test default keymap"

![Keymap testing](https://thepracticaldev.s3.amazonaws.com/i/crszohsjhhup1eflsuc3.png)

Nope, it's just a prompt to check you had the right keymap, which is not my case, so I cancel it and select my language's keymap. Apparently, it doesn't want to show some special characters (such as ñ or letters with accents), but the rest of the keys print the correct characters for my keyboard, so I'll move on.

After the keymap, I'm asked for a hostname (I respond with *bsdchamber*), and I'm asked about what to install. Since I'm not sure, I just prefer to leave as is and select OK.

![Software selection?](https://thepracticaldev.s3.amazonaws.com/i/gw7bsz3eon6085om19vd.png)

Next, I get to the partitioning. Thankfully, I don't really need to do any specific stuff, so I just select the default option and tell it to use the entire disk and create an MBR partition scheme.

![Partioning](https://thepracticaldev.s3.amazonaws.com/i/peyf99uk2p8zvi5prjws.png)

And this is how the final partitioning setup looks like (the device names are quite interesting, by the way):

![Disk setup](https://thepracticaldev.s3.amazonaws.com/i/761dfse4fc8dvkdg6rfg.png)

Once it's finished, it begins copying all the data to the hard-drive:

![Copying data](https://thepracticaldev.s3.amazonaws.com/i/2s483x6xqnaief0jic7e.png)

Suddenly, I'm prompted to enter a root password:

![Root password](https://thepracticaldev.s3.amazonaws.com/i/dc67pnem9j6pqim483o8.png)

And then it asks me to select a network interface and asks me whether I want to configure IPv4, DHCP, and IPv6. I only accept the first two. Then, I'm prompted to the DNS selection.

![DNS choosing](https://thepracticaldev.s3.amazonaws.com/i/q2l4u0k6xd63ouz3w06y.png)

This is quite surprising to find nowadays, but I still fill them in with the Google Public DNS addresses.

After that, the timezone selector pops out, and I select my timezone without any problem at all. I also get to this system configuration:

![System](https://thepracticaldev.s3.amazonaws.com/i/1asibj5w11ei4ssmbvhp.png)

Good, SSH is already included, but I still want the NTP daemon (for syncing up the time), so I select them with the space bar and move on.

![Hardening](https://thepracticaldev.s3.amazonaws.com/i/ulyy50utqhynzh8vuubj.png)

This screen is quite interesting, and probably a reason why they say FreeBSD has somewhat better security than Linux. Oh well, I'll just select what feels more natural to me, including *secure_console*. Once I click OK, it asks me whether I'd like to add new users. I probably should, but since this is just a lab, there's no need to do so, so I pass, and I land on the final screen.

![Final screen](https://thepracticaldev.s3.amazonaws.com/i/9comhztlh6odo9ipolvc.png)

Well, at least you can change something up if you change your mind, but I'll just exit and finish the installation. It also asks about manual configuration, but I prefer not to do so. After that, I reboot to the new installation, even though I have to remove the virtual disc manually.

# First boot

![First login](https://thepracticaldev.s3.amazonaws.com/i/mklmv4k3ys8lecm0n4c6.png)

Since I selected *secure_console*, I do have to put credentials to enter into a shell, just like I'm used to in Debian-based distributions, and it works pretty much the same. In fact, the command line format seems to be exactly the same, even if it looks quite ugly.

![The shell](https://thepracticaldev.s3.amazonaws.com/i/8oimwiq1xhsg68l0ck49.png)

I try the "ifconfig" command to check the network, and, sure enough, it is identical as in Linux. Next, I try to login via SSH.

![Unable to connect](https://thepracticaldev.s3.amazonaws.com/i/a3j5hvg7fyo85hwn3i5f.png)

Strangely, it refuses to accept my password, but I suspect it's probably due to the fact that I'm trying to login to the root user. I guess I'm creating another user, after all, al least just to get started.

![Adding an user](https://thepracticaldev.s3.amazonaws.com/i/9xopo7rcraq2os0zxg3a.png)

It looks like the "adduser" command I used works a bit differently than I expected, but I still managed to create a user for me. I'll try entering with that one instead.

![Login](https://thepracticaldev.s3.amazonaws.com/i/t9qcivllrdpkarfw8446.png)

And it looks like we have a winner! I shouldn't be surprised, anyway, as root login via SSH isn't allowed when security measures are applied to Linux machines. Luckily, I should be able to enter as root with this brand-new user.

![Su Sorry](https://thepracticaldev.s3.amazonaws.com/i/ky0krzxaka0i2d91o46y.png)

Or maybe not. I'll have to check the manual. "man su" should do it.

![su manual page](https://thepracticaldev.s3.amazonaws.com/i/3zqq6yl92ktg29yu9wh7.png)

Well, this is interesting. It looks like I have to add my own user to the group "wheel" if I want to be able to log in as root. But, first of all, I should figure out how to add a user to a group. I used to do it with "adduser", but it probably won't work here, especially knowing what happened before. The manual itself says that "adduser" is just for creating new users.

Sadly, after trying to check some manual pages and listing the commands in /usr/bin, I can't find anything at all, so I guess I'll have to edit the /etc/group file manually.

![No nano available](https://thepracticaldev.s3.amazonaws.com/i/lsl7g2y7e7zfh14xrc5o.png)

Oh, great, I don't have nano installed. That's... the only text editor I can really use, so I'll have to install it. Luckily, I saw that you could install stuff in the login message by typing "pkg install", so hopefully "pkg install nano" will work?

![Installing nano](https://thepracticaldev.s3.amazonaws.com/i/qaetm7lrvz1hftgx3la0.png)

Phew! It needed to do some more stuff, as it was the first thing I was installing via pkg, but it worked, so now I should be able to edit the file easily.

![Editing /etc/group](https://thepracticaldev.s3.amazonaws.com/i/08o2dg27c0b76gp5j6nt.png)

Okay, now that thing's done, will it allow me to...?

![Using su to log in as root](https://thepracticaldev.s3.amazonaws.com/i/droflgejr0a2nirj5qs5.png)

It does, luckily. And I notice right away that my user's home path is slightly different than usual. I'll have a look at the root directory.

![The root directory](https://thepracticaldev.s3.amazonaws.com/i/y83zd982u9v9b5bksso4.png)

There are a few folders that I don't recognize, but otherwise, it is very similar to what I'm used to seeing when working on Debian. I should also see what shell I'm using, just in case.

![FreeBSD's users](https://thepracticaldev.s3.amazonaws.com/i/53mxj7u70vzqvyfmx5s3.png)

So root is using "csh"... I really thought I was using bash, since it was so similar, but I guess that being able to see *hidden* files was a dead giveaway of the fact something was off. In fact, I can't recognize any of the files that are present in root's home. Still, what I feel the most comfortable on is bash, so I'm going to try to install it.

![There's bash](https://thepracticaldev.s3.amazonaws.com/i/vg64j67p977kc0vtwjf6.png)

Nice! It's included! Once I get it installed, I grab its location by using "which", and change it up in the /etc/passwd file.

![Changing the shell](https://thepracticaldev.s3.amazonaws.com/i/7kpj4rpaxzluu77r87fg.png)

I save the file and exit the connection, just to enter again and log in as root. After seeing the shell looks exactly the same, I decide to see all processes running (at least, from my user's perspective).

![Processes](https://thepracticaldev.s3.amazonaws.com/i/j4wuxhafwkfhymgtwgz6.png)

As I imagined, the changes didn't apply, and since I'm not looking at the proper command to do it, I just prefer to reboot the machine so that the changes take effect. A simple "reboot" will do it.

Unfortunately, that doesn't work, and I'm still stuck with csh. However, I notice there's another file, master.passwd, so I try to modify that one.

![master.passwd](https://thepracticaldev.s3.amazonaws.com/i/mlecmjftk2liwgyqiai0.png)

This one seems to have the root password, but it looks exactly the same as the other file otherwise. I save and reconnect to the host, but it doesn't work, either, so I search on the Internet, and I land on [this page](https://www.freebsd.org/doc/en_US.ISO8859-1/articles/linux-users/shells.html), which shows the command "chsh" in order to do what I wanted. I try "chsh root", but it takes me to a vi editor. Luckily, I happen to find another manual entry, where it says I can change it by setting the EDITOR variable, which is done with "setenv EDITOR nano", in my case.

![Changing the shell with nano](https://thepracticaldev.s3.amazonaws.com/i/xcyzqg6hy2mgasv6ktsz.png)

But it fails. It simply refuses to accept that shell as valid.

![No bash for root](https://thepracticaldev.s3.amazonaws.com/i/w5mch1bui9e87fcsnnzf.png)

Out of curiosity, I tried changing my non-root user's shell. And surprisingly, it did work!

![Bash is accepted here](https://thepracticaldev.s3.amazonaws.com/i/7tbcoy8vehvcex3dspbr.png)

I had seen before that the manual pages advised against changing the default shell, but I didn't expect that it wouldn't let me do so. Oh well, I'll have to deal with it.

----

This is it for the moment. In the next part, I'll be trying to install the LAMP stack on FreeBSD and then a desktop environment.