Hello, friends in this post I will show you how to enable sudo in FreeBSD 12. We like Linux but also FreeBSD for its robustness and for being another valid alternative for servers.
What is sudo?
In a PC that runs some Linux distribution or FreeBSD, there are different users. Each of them has defined roles and permits. For example, to install a package in FreeBSD it is necessary to do it with root user privileges. Then, not all users can do all things.
The sudo program is part of the GNU suite. It is a small application that allows the execution of commands with the security privileges of another user. Normally, this “other” user is root.
By FreeBSD security policy, this program is not enabled for your regular user. And the truth is that if you use FreeBSD on your personal computer we can enable it and it would not be a problem. However, if you install FreeBSD to be used on a server, you should not do it.
In any case, sudo allows you to execute commands that your user can not. In addition, the commands that are applied with sudo are not registered in the system log.
Enabling sudo on FreeBSD 12
We already know that sudo is not installed by default on FreeBSD, but it is available from the official repositories. So first log in as root on FreeBSD.
After you have opened the terminal session as the root user, install sudo with the following command:
:~$ pkg install sudo Updating FreeBSD repository catalogue... FreeBSD repository is up to date. All repositories are up to date. The following 1 package(s) will be affected (of 0 checked): New packages to be INSTALLED: sudo: 1.8.31 Number of packages to be installed: 1 The process will require 3 MiB more space. 730 KiB to be downloaded. Proceed with this action? [y/N]:
Once you have installed sudo, you need to add your user to the list of users who can run sudo.
To do this, first install the nano text editor which is easier to use than vi.
:~$ pkg install nano
And now we have to edit the sudo configuration file.
:~$ nano /usr/local/etc/sudoers
Now under the line:
root ALL=(ALL) ALL
Add the next line:
angelo ALL=(ALL) ALL
In this case, angelo is my username. Replace it with yours.
Save your changes with CTRL + O and close the editor with CTRL + X.
Now you can log out as root and log in with your regular user.
The first time you run a command with sudo, such as updating the system, you will see something like this:
Just enter your password and the command will be executed.
Remember that sudo opens a security hole. So normally it is not recommended to use it on servers. But still, it can be very useful to keep it in mind.
And that’s it, now you can use sudo in FreeBSD 12.
Conclusion
Many times we need to execute various commands as the root user to perform operations on our Unix-based systems. However, we do not always have access to the root user and thanks to sudo we can do it. On the other hand, sudo is not always enabled in production environments.
Now you know how to enable sudo in FreeBSD 12.