1. Open System Preferences | Users and Groups
2. Click on the lock and authenticate with an administrator account.
3. Click Login Options...
4. Click the "Edit..." or "Join..." button at the bottom right.
5. Click the "Open Directory Utility..." button.
6. Click the lock in the Directory Utility window and authenticate with an admin account.
7. Choose 'Enable Root User' from the Edit menu.
8. Enter the root password you wish to use and click OK.
To disable the root user follow the same steps but choose 'Disable Root User' from the Edit menu in step 7
The user named "root" is a special user in UNIX-style operating systems that has read and write privileges to all areas of the file system. Usually, root login is disabled.
The root user should only be used for specific administration or monitoring tasks. After completing a task as the root user, you should log out of macOS.
Related macOS commands:
ht1528 - Enabling and using the 'root' user in macOS.