MAC USER ACCOUNTS | create with terminal

https://miapple.me/fixing-mac-no-admin-account-macos-mojave-later/

If your Mac has no admin account anymore or if your macOS account lost its administrator rights on macOS 10.14 Mojave, macOS 11 Big Sur or later, you can recover the macOS admin rights easily by running again Apple’s Setup Assistant tool to add a new admin account. For getting in the setup process, you have to remove the file “.AppleSetUpDone” via Terminal or macOS Recovery mode. Then, you can recover the admin rights of your original admin account via the new administrator account. After that, you can reboot into your recovered one and delete the interim admin account.

Note: The following fixes apply to macOS Mojave 10.14, macOS Big Sur 11 and later. For macOS High Sierra 10.13 and earlier, fixing Mac no admin account is solved via the “Command – S” (SUM = Single User Mode) route which is deactivate in later macOS versions: How To Recover Lost Admin Rights On macOS High Sierra and Sierra, Mac OS X El Capitan And Yosemite

Fixing Mac no admin account on macOS delete File .AppleSetUpDone

Fixing Mac no admin account on macOS delete File .AppleSetUpDone

The following fix “Mac no admin account” works if you lost admin account and admin rights

  • during upgrading, e.g. from OS X 10.13 High Sierra to macOS Mojave 10.14 or to macOS Big Sur 11
  • after restoring your Mac from backup, or
  • after making heavy modifications to the system

The above mentioned situations can result in destroying or downgrading your admin account to a standard user account with no admin rights. In consequence, you cannot log in to your admin account or cannot use it for changing system settings.

Even though the Setup Assistant only runs once when you first install Mac OS X / macOS, it remains on your computer and is prevented from running by the presences of a hidden file called ‘.AppleSetupDone‘ in a system folder on your Mac. Therefore, to go through the Setup Assistant again you can create a fresh admin account, you simply need to remove this file:

Mac no admin account: How to recover admin rights by deleting .AppleSetupDone file via Terminal

  1. Open Terminal in macOS.
  2. Change the directory: Type cd /var/db and hit enter tab.
  3. Run the following command to remove file “.AppleSetupDone”: Type sudo rm -f ./.AppleSetUpdone and hit enter tab.
  4. Restart your Mac and go through the Setup Process. Create a new account and take a DIFFERENT username than your Standard user account (e.g. “Backup Admin”)
  5. After logging in, open System Preferences and select your Standard user account and check the box labeled “Allow user to administer this computer” (Note: if the box is grayed out, click the lock icon the lower left to enabled editing)
  6. Log out of your Mac and log in in as your original account.
  7. Either delete the Admin account you created in step 4 or, even better, leave it as a backup account.

Mac no admin account: How to recover admin rights by deleting .AppleSetupDone file via macOS Recovery Mode

  1. Shut down your Mac.
  2. Reboot your Mac and press and hold “Command + R“.
  3. At the “macOS Recovery”-Screen select a user, click on “Next” and enter the user’s password. Note: If you do not know the password click on “Forgot all passwords” and sign in with your Apple ID. This step is needed if you secured your Mac with FileVault.
  4. On the next screen select Disk Utility and mount all internal discs, especially “Macintosh HD – Data“.
  5. Close Disk Utility and open Terminal via selecting Utilities and then Terminal.
  6. At the prompt (in my case [-bash-3.2#]) type cd /Volumes/”Macintosh HD”/var/db and hit enter tab.
  7. Run the following command to remove file “.AppleSetupDone”: Type rm -f ./.AppleSetUpdone and hit enter tab.
  8. Then reboot your Mac: Type reboot and hit enter tab.
  9. Your Mac reboots. Go through the Setup Process. Create a new account and take a DIFFERENT username than your Standard user account (e.g. “Backup Admin”)
  10. After logging in, open System Preferences and select your Standard user account and check the box labeled “Allow user to administer this computer” (Note: if the box is grayed out, click the lock icon the lower left to enabled editing)
  11. Log out of your Mac and log in in as your original account.
  12. Either delete the Admin account you created in step 4 or, even better, leave it as a backup account.

Lost access to admin account on macOS 10.14 Mojave or later, can easily restored by reactivating Apple’s Setup Assistant tool through deleting the file “.AppleSetupDone” via terminal or macOS recovery mode. After rebooting your Mac or MacBook you walk through the process to set up a fresh administrator account with full admin rights.




https://osxdaily.com/2015/02/19/enable-disable-root-command-line-mac/

 

For those who are familiar with the Terminal and comfortable with command line syntax, enabling the root user account in Mac OS X from the command line may even be easier than doing so from the Directory Utility application, as there are fewer steps necessary to both enable and disable the root user account, either widely or on a per-user basis. This is also advantageous in that it can be enabled remotely via SSH on any Mac that can be connected to.

It’s very important to point out that enabling the root user account is only for advanced users who understand when and why it may be necessary to have universal superuser privileges. This is rarely necessary for anything beyond systems administrators or for troubleshooting some particularly advanced and complex issues, and for the vast majority of purposes, simply using sudo or launching a GUI app as root is usually sufficient for the vast majority of situations.

If you do not know what you’re doing, do not enable the root user account, and do not use the root user account. Because the root user has universally privileged access to everything in Mac OS X, it’s quite easy to mess something up, and leaving the account active can lead to a security risk. This is truly only for advanced Mac users.

Enable root User Account from the Command Line of Mac OS X with dsenableroot

A simple command line tool appropriately called ‘dsenableroot’ will quickly enable the root user account in Mac OS X. At it’s most simple form, simply type ‘dsenableroot’ into the Terminal prompt, enter the users password, then enter and verify a root user password.

% dsenablerootusername = Pauluser password:root password:verify root password:dsenableroot:: ***Successfully enabled root user.

When you see the “dsenableroot:: ***Successfully enabled root user.” message, you know the root user has been enabled with the password that was just defined.

If you wish, you can also enable the root user on a per user account basis by specifying the -u flag:

dsenableroot -u Paul

Replacing ‘Paul’ with any user name that is on the specific Mac will work.

Of course, once you’re done with root user, you may wish to disable root account access as well.

Disable Root User Account from the Command Line in Mac OS X

Passing the -d flag to the same dsenableroot command string will disable the root user universally, like so:

% dsenableroot -dusername = Pauluser password:dsenableroot:: ***Successfully disabled root user.

The message “dsenableroot:: ***Successfully disabled root user.” indicates the root account is now disabled.

Similar to enabling a specific user, you can also disable for a specific user with the -d and -u flag:

dsenableroot -d -u Paul

This may be appropriate for a situation where a particular user account no longer requires root account privilege.

Terminal in Mac OS X

Generally speaking, leaving the root user account disabled is a good idea.

The dsenableroot utility works in MacOS Sierra, OS X El Capitan, OS X Yosemite, OS X Mavericks, Mountain Lion, etc. For users who are on much older versions of OS X like Snow Leopard, use the sudo passwd method instead.




How To Create An Admin Account In The Mac Terminal

img

Nik May 23, 2021

Send Email

The terminal is a Mac utility that is often overlooked because some users find it arcane. But it provides an opportunity to customize elements of your Mac by using command line prompts. This way, you can perform tasks that would otherwise require additional software.

How to Create an Admin Account in the Mac Terminal

One advantage of using Terminal is that you can quickly create a new admin account, replace an admin, or add new users on your Mac. In this article, we’ll go over all the details regarding how to use Terminal as a Mac administrator, and we’ll answer a few commonly asked questions.

How to Create an Admin Account on a Mac Using Terminal

Creating a new admin account using Mac’s graphical interface is often the fastest option, but there are times when using Terminal is a preferable option.

For example, if you’re troubleshooting an issue remotely via the Screen Sharing feature, you’ll need to open Terminal. Before diving into the steps you’ll need to take to create an administrator account using Terminal, let’s find out where you can find this utility:

  1. Go to the “Finder” app and then select “Applications.” img
  2. Scroll down and double-click on the “Utilities” folder. img
  3. Find Terminal and open it. img

Now, follow these steps to make a new administrator account:

  1. Type in
    sudo dscl . -create /Users/username
    and then hit enter. Then change the “username” part with one word of your choosing. Type in a new password and hit “enter” again. img
  2. Type in
    sudo dscl . -create /Users/username UserShell /bin/bash
    and hit “enter “again. img
  3. Now add the following command:
    sudo dscl . -create /Users/username RealName
    “Jane Smith”
    and hit “enter.” img
  4. The next step is to type in
    sudo dscl . -create /Users/username PrimaryGroupID 1000
    followed by “enter.” img
  5. Continue by typing in
    sudo dscl . -create /Users/username NFSHomeDirectory /Local/Users/username
    and hitting “enter.” This prompt creates a new user folder. img
  6. To replace the password, type in
    sudo dscl . -passwd /Users/username password
    followed by “enter.” Choose a new password you’ll use every time you log in.
  7. To give the user administrative privileges, type in “sudo dscl . -append /Groups/admin GroupMembership username” and hit “enter.”

How to Create an Admin Account in Mac Terminal

How to Make Yourself an Administrator From the Terminal on Mac

If you’re using a Mac on which you don’t have an administrative role, you can change that by entering specific commands in Terminal.

That will give you permission to change important settings, as well as other privileges such as installing new programs. Here’s how you can change an existing user account to an administrative account via Terminal:

  1. Open the Terminal app following the same steps listed above.
  2. Type in
    sudo dscl / -append /Groups/admin GroupMembership USERNAME
    and replace “username” with your name.
  3. Now enter the administrative password.

You will get an administrative function upon executing that command. Keep in mind that you must have the administrative password to make this change in the first place.

How to Change Your Username on Mac

You can easily change your username on macOS, but you need to change the name of the home folder as well for it to work. So, here is how to change the name of the home folder:

  1. Log in to the administrative account on your Mac.
  2. Open the Users folder on the account you want to rename.
  3. Rename the home folder, but make sure there are no spaces in the name. You’ll need to enter the administrator’s name and password.

The next step is renaming the Mac user account:

  1. From the admin account on Mac, follow the path Menu>System Preferences. img
  2. Select “Users & Groups” and click on the lock icon. Then enter the admin name and password. img
  3. Click on the user you want to rename and select “Advanced Options.” img
  4. Enter the same name you used for the home folder. img
  5. Go to “Home directory” and change the account name to match the home folder as well. img
  6. Select “Ok” and then restart your computer. img
  7. Next time you log into the newly renamed account, make sure all the files and folders are visible.

How to Create an Admin Account in a Single User Mode

The first thing you need to do to create an admin account from a Single User Mode is shut down your Mac. Then restart it in a Single User Mode by turning it on while pressing and holding “Command + R.” Then follow these steps:

  1. Enter
    /sbin/mount -uw /
    command when prompted and press “enter.”
  2. Next, type in
    rm /var/db/.applesetupdone
    and hit “enter.” This will remove the file that tells the OS the setup process has been performed before.
  3. When this file is removed, you need to restart your Mac again.
  4. Next time the Mac reboots, you’ll see a “Welcome to Mac” window on the screen. You can follow the prompts to make a new admin account.

How to Create Admin Account in a Mac Terminal

Frequently Asked Questions

We’ve included some more information for you in this section.

How Does Terminal Work on Mac?

 

The terminal is an app found in the Utilities folder inside all Mac devices. It has a Unix command-line system, which some users prefer.u003cbru003eu003cbru003eEvery command you use in Terminal contains three elements. The first is the command itself. The second is the argument that provides the information about the resource on which the command operates. And the third is having the option for modifications of the output.

Can I Have Multiple Administrator Accounts on My Mac?

 

The answer is yes. Your Mac can have more than one administrator account. You can also change standard or share-only user accounts to administrator accounts.

How Do I Create User Accounts From the Terminal in macOS?

 

To create a user account from Terminal in Mac, follow steps 1-6 in this article under u0022How to Create an Admin Account on a Mac Using Terminal.” All you need to do is skip the final step, and you’ll have the standard user account.

Managing Your Mac Admin Accounts

The macOS graphic interface allows users to create new admin accounts and add and remove admin privileges as well. But in some instances, accessing this feature via the Terminal app is faster and simpler.

It’s also a great way to get acquainted with the basics of how macOS works. Follow the steps we’ve provided to add new admin accounts via Terminal.

Scroll to Top