Prerequisite
FreeBSD 14.2
以 root 登录终端进行操作
实践操作
将用户添加到 wheel 组
pw usermod microcharon -G wheel
验证用户是否已添加到 wheel 组
root@freebsd-test:~ # id microcharon
uid=1001(microcharon) gid=1001(microcharon) groups=1001(microcharon),0(wheel)
确保 /etc/pam.d/su 配置正确
确保这行未被注释
auth requisite pam_group.so no_warn group=wheel root_only fail_safe
root@freebsd-test:~ # cat /etc/pam.d/su
#
#
# PAM configuration for the "su" service
#
# auth
auth sufficient pam_rootok.so no_warn
auth sufficient pam_self.so no_warn
auth requisite pam_group.so no_warn group=wheel root_only fail_safe ruser
auth include system
# account
account include system
# session
session required pam_permit.so
使用 su 或 sudo 切换至 root
默认情况使用 su -
microcharon@freebsd-test:~ $ su -
Password:
若使用 sudo
,则需要安装和配置 sudo
pkg install sudo
配置 sudoers 文件
visudo
添加用户权限,找到以下行并取消注释
## Uncomment to allow members of group wheel to execute any command
# %wheel ALL=(ALL:ALL) ALL
%wheel ALL=(ALL:ALL) ALL
使用 sudo
sudo -i
参考资料
How To Add, Delete, Grant Sudo Privileges to user on FreeBSD - nixCraft