How To Install And Use sudo In FreeBSD?


The sudo (superuser do) is a program for Unix like operating systems. It allows a user to run a command or program with the privilege of another user, by default superuser. It comes preinstalled in various Linux distributions, but if you want to use it in FreeBSD then first you need to install it.

In this article, we will discuss installing and using sudo in FreeBSD.

How to install sudo in FreeBSD

There are two ways to install software packages in FreeBSD: pkg and ports collection. Pkg is used to install packages from prebuilt binaries while ports collection is a much more customizable option, a user can decide how a port or package will be compiled and installed on a system.

You will have to execute the given command as root or with superuser privileges.

Installing sudo using pkg

Use the following command to install sudo using pkg –

pkg install sudo

Installing sudo using the ports collection

To install the sudo from the ports collection use the following commands –

cd /usr/ports/security/sudo

And then run –

make install clean

Configuring sudo

In FreeBSD /usr/local/etc/sudoers file contains a list of users or users group to execute the program that requires the privilege of another user. By editing, this file sudo can be configured to require a password.

Run the following command and uncomment the wheel and sudo group so that the members of these groups can use sudo.

visudo /usr/local/etc/sudoers

Now you can add a user to either of these groups so that it can execute a command with the privilege of another user or superuser. To add a user to a group you can use the given command in your terminal –

Execute the given commands as root or with superuser privileges.

pw groupmod group_name -m user_name

For example to add a user lalit to wheel group use –

pw groupmod wheel -m lalit

or to add a user lalit into sudo group use-

pw groupmod sudo -m lalit

Now the user lalit is allowed to use sudo to execute a command.

How to execute a command using sudo

To execute a command using sudo in FreeBSD use the command as given below.

sudo /path/to/command

For example, to install a software in freebsd requires superuser privilege, so you can run the given command to install a package –

sudo pkg install nano

This will ask you to enter your password, enter it to proceed with the installation process.

Ok, that’s all for now. If you have any thoughts on this topic, you can share it with us in the comments below.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.