FreeBSD is Unix like general-purpose operating systems. FreeBSD provides various tools to add, modify, and remove local user accounts using the CLI. This page shows how to add users on FreeBSD operating systems using useradd and pw commands.
Add users on FreeBSD
The procedure is as follows:
- Open the terminal app
- Switch to root user account using sudo -i OR su -
- Run adduser command for adding new users on FreeBSD interactively
- Delete user using rmuser command
Let us see all examples in details. First, list all shells on system using the grep command:
grep '/bin/' /etc/shells
Creating FreeBSD users from the command line using adduser
Log in as root user using the sudo command/su command:
sudo -i
Create the vivek user on FreeBSD, run:
adduser
Adding a user on FreeBSD using adduser command
Confirm that user exists in the system
Run the following cat command or grep command/egrep command:
cat /etc/passwd
tail -1 /etc/passwd
grep '^username' /etc/passwd
grep '^vivek' /etc/passwd
Confirm that FreeBSD users exists in the system using various commands
How do I change or set the password for vivek user
Run the passwd command as follows:
passwd vivek
FreeBSD allow sudo privileges for user
Make sure sudo is installed on FreeBSD and wheel group is allowed as follows:
# visudo
Sample outputs:
## Uncomment to allow members of group wheel to execute any command %wheel ALL=(ALL) ALL
Save and close the file. Any FreeBSD user who is a member of the wheel group can run a command using sudo. Use the id command to find out if vivek is part of wheel group
# id -Gn vivek
vivek wheel
If not add user vivek to the wheel group, run:
# pw groupmod wheel -m vivek
Verify it using the /etc/group file
# id -Gn vivek
# grep '^wheel' /etc/group
How to delete or remove user account
The rmuser command removes one or more users submitted on the command line or from a file in FreeBSD operating system. Run:
# rmuser username
# rmuser
## delete user named marlena
# rmuser marlena
Delete the FreeBSD user along with any personal data of the user
grep '^marlena' /etc/passwd
cat /etc/passwd
id marlena
Sample outputs:
id: marlena: no such user
How to use pw command
The pw command create, remove, modify & display system users and groups. It has many more options. For example:
pw user help
pw user add help
pw user del help
pw user mod help
pw group help
pw lock help
pw unlock help
In this example, add user named marlena as follows:
# pw user add -n marlena -c 'Marlean Root' -d /home/marlena -G wheel -m -s /usr/local/bin/bash
Where,
- -n marlena : login name
- -c 'Marlena Root' : user name/comment
- -d /home/marlena : home directory
- -G wheel : additional groups (add to wheel group)
- -m : create and set up home
- -s /usr/local/bin/bash : name of login shell
One can local and unlock FreeBSD user using the pw command:
# pw lock marlena
# pw unlock marlena
See pw command man page for more info:
man pw
Conclusion
This page demonstrated how to create several users on your FreeBSD Unix box, set passwords for those users, and delete them if the need arises using various commands.
🐧 1 comment so far... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
Comments on this entry are closed.
Have a question? Need help adding a new users to FreeBSD? Post it to our forum thread.