Easy to Create Users and Groups on the FreeBSD System

The FreeBSD system allows multiple people to use the machine simultaneously. Even though only one person can control the system completely, any number of users can log into a FreeBSD machine over a network that has been granted access rights. To access the system, each user must have a unique user account.

FreeBSD, like other Unix-like operating systems, allows users to create accounts to access the system interactively. If managed properly, user accounts can provide a layer of system security by allowing users to access only the files and folders they need to complete their tasks. Usually the user has a user and group that belongs only to that person and is protected by a unique password.

In FreeBSD, groups are basically just catalogs of user accounts. Each Group in FreeBSD has a group name and a GID, or Group ID associated with it. Groups work in FreeBSD just like how they work in other Unix Operating systems, and each process has a list of groups associated with it. With this list of groups, the User ID determines the actions that a process is allowed to perform to make changes in the system.

1. How to Create a User

To add a new user, you can use the adduser utility. This utility can be run interactively, with a request to collect information about new users, or non-interactively, which is preferable for adding several users at once. When a new user is added, this utility automatically updates /etc/passwd and /etc/group. Using the adduser script will also create or form a folder.

The adduser utility is interactive and walks through the steps to create a new user account. As seen in Adding a User on FreeBSD, enter the required information or press Return to accept the default values shown in square brackets. Below is an example of using the adduser script.

root@router2:~ # adduser
Full name:
nasi uduk
Uid (Leave empty for default):
Login group [nasi]:
Login group is nasi. Invite nasi into other groups? []:
Login class [default]:
Shell (sh csh tcsh bash rbash git-shell nologin) [sh]:
Home directory [/home/nasi]:
Home directory permissions (Leave empty for default):
Use password-based authentication? [yes]:
Lock out the account after creation? [no]:
Username : nasi
Password : <disabled>
Full Name : nasi uduk
Uid : 1004
Class :
Groups : nasi
Home : /home/nasi
Home Mode :
Shell : /bin/sh
Locked : no
OK? (yes/no):
adduser: INFO: Successfully added (nasi) to the user database.
Add another user? (yes/no):
root@router2:~ #

The example script above creates a user with the name nasi and is in the /usr/home/nasi folder.
Apart from the example above, another way to create a new user is with the "pw" script as in the following example.

root@router2:~ # pw add user -n mahameru
Using the script above creates a new user with the name "mahameru" and without creating or forming a folder. Now we try again with another script.

root@router2:~ # pw useradd -n bromo -s /bin/csh -m
The script above is used to create a bromo user and create a new folder at home in the /usr/home/bromo directory. So the script is the same as the adduser script. Now let's try, inserting the bromo user into the group wheel.

root@router2:~ # pw usermod bromo -g wheel
We can run the script above, provided that the bromo user has been created first, if the bromo user has not been created. the above command will not work.
Now we will create a user by placing the user file structure into a special directory, for example we will create the user Papandayan and we will place it in the /usr/home/everest folder.

root@router2:~ # pw useradd -m -n everest -d /usr/home/everest
After we have successfully created a user, now we will display information from that user, use the following script to display user information.

root@router2:~ # pw show user mahameru

2. How to Create a Group

Groups are lists of users. Groups are identified by their group name and GID. In FreeBSD, the kernel uses the UID of a process, and the list of groups it belongs to, to determine what the process is allowed to do. To create a group we can use the "pw" script.
Below is an example of creating a rinjani and argopuro group.

root@router2:~ # pw groupadd rinjani 
root@router2:~ #
pw groupadd argopuro
Now let's try to create a Sindoro group and a Welirang user, then we put the Welirang user into the Sindoro group. To carry out these commands we use a script.

root@router2:~ # pw groupadd sindoro -M mahameru
Enter the bromo user again into the sindoro group, so that the sindoro group has 2 users, namely user mahameru and user bromo.

root@router2:~ # pw groupmod sindoro -m bromo
Now we look at the GID of the group that we created above.

root@router2:~ # pw groupshow sindoro
root@router2:~ #
pw groupshow rinjani
root@router2:~ #
pw groupshow argopuro
root@router2:~ #
To see the current active users and the group membership of these users use the "id" command.

root@router2:~ # id rinjani

3. How to Delete Users and Groups

After we know the technique for creating users and groups, now we will delete the user and group. First we will delete the user, use the command pw userdel or pw deluser.

root@router2:~ # pw userdel mahamaeru
root@router2:~ #
pw deluser bromo
The script above is used to delete user mahameru and rinjani. How do I delete a group? Use pw groupdel to delete a group.

root@router2:~ # pw groupdel rinjani
root@router2:~ #
pw groupdel argopuro
After we practiced how to create users, groups and how to delete them, it turned out to be very easy to implement on a FreeBSD machine. Once you have mastered the material above, you can immediately put it into practice by setting restrictions on the use of access rights on the FreeBSD server at your office, school or home.
Iwan Setiawan

I Like Adventure: Mahameru Mount, Rinjani Mount I Like Writer FreeBSD

Post a Comment

Previous Post Next Post