Open programs with root privileges on a Mac

Author: Roger Morrison
Date Of Creation: 18 September 2021
Update Date: 1 July 2024
Anonim
How To Enable Root User On Mac OS
Video: How To Enable Root User On Mac OS

Content

You can open any program on a Mac with root privileges, as long as you have an administrator password. However, you should only use root access if you know what you are doing, because if something goes wrong you can damage the program or your computer.

To step

Method 1 of 3: From an administrator account

  1. Understand the risks. Most graphics programs are not designed for root access. Only perform specific tasks that you understand well, as the wrong action can result in inaccessible files, faulty programs, or security vulnerabilities.
  2. Open Terminal. Log in to your computer with an administrator account. Go to Applications → Utilities and open Terminal.
    • The administrator account cannot be blank, otherwise Terminal will not grant you access to root privileges.
  3. Try the quick way. Using the command "sudo" you can open programs with root access, but this requires the file path to the executable file in the program package. Most Mac and third-party programs have the package contents organized in the same way, so try the following first:
    • Enter: sudo file path from hard drive to program.app / Contents / MacOS /name of the program.
      For example, to open iTunes, type sudo /Applications/iTunes.app/Contents/MacOS/iTunes and press ⏎ Return.
    • Enter the password of the administrator account you are currently logged in with. Press ⏎ Return.
    • If the command works, the program should open with root privileges. If Terminal shows "command not found", proceed to the next step.
  4. Open the package contents of the program. If the quick way did not work, you must first search for the program in Finder. Click with your right mouse button (Control and click) on the program icon and select Show Package Contents from the drop-down menu.
  5. Find the executable file. You will see one or more folders in the program package. Look for the executable file in this folder. You can usually find it in / Contents / MacOS.
    • Usually the executable has the same name as the program, but it can also have a different name, for example "run.sh".
    • The icon of the executable file is normally a black square containing the word "exec" in lowercase.
  6. Type "sudo" in Terminal. Type sudo followed by a space. Do not enter the command yet.
  7. Drag the executable file into the Terminal window. Now the exact location of the executable is automatically displayed in the line after "sudo".
  8. Confirm the command with your password. Press ⏎ Return. Enter the password of the administrator account you are currently logged in with and press again ⏎ Return. Now the program will open with root privileges.

Method 2 of 3: From an account that is not the administrator account

  1. Open Terminal with an account that is not the administrator account. Many system administrators prefer to work from a normal user account to minimize possible damage from errors or malware attacks. You will need the administrator password for this method, but you can temporarily gain root access without switching users. To do this, first open a Terminal window.
  2. Switch to an administrator within Terminal. Enter the command su - followed by a space and an administrator password for this computer. Enter that administrator password. Now you work from that user.
    • The dash in the command is optional, but it is recommended. It sets the environment variables and user folder of the administrator, which can prevent accidental damage.
  3. Open the program with the command "sudo". The command is usually applied like this: sudo file path from the hard drive to the program.app / Contents / MacOS /name of program. If this doesn't work or you need more help, see the admin instructions in the previous section.
  4. Return to your own account. When you have completed all tasks that require root privileges, enter exit in the Terminal window. This will exit the administrator account and return to your normal account.

Method 3 of 3: Troubleshooting

  1. Disable "System Integrity Protection". This security technology was introduced in Mac OS 10.11 El Capitan, and it restricts access to important files, including for the root user. If it is not possible to make the desired changes, you can turn off SIP. Only do this if you know what you are doing, understand that an error can lead to the complete wipe of your computer or cause a computer to stop working:
    • Restart your computer. Press the key combination ⌘ Command + R. after you hear the startup chime. Now it will boot into recovery mode.
    • Select Utilities from the top menu, then select Terminal.
    • Enter the following code in Terminal: csrutil disable; reboot.
    • Allow the computer to restart normally. Now you can use the steps above to open any program you want with full root privileges. When you are done, it is a good idea to repeat these instructions with enable instead of disable to re-enable SIP.
  2. Use "nano" instead of a graphical text editor. In some cases, it is safer and more reliable to edit configuration files with a text editor within Terminal. Nano is a simple option and it comes standard. To use it with root privileges, enter sudo nano in Terminal, followed by a space and the file path to your text document. Now you can edit the document from Terminal. When you are done, press Control + O to save it, then on Control + X to exit nano.
    • For example, the sudo nano / etc / hosts code opens the "hosts" file with root access.
    • It's always a good idea to make a backup before editing any configuration files. You do this by means of the following code: sudo cp file_path_of_configuration_filenew_file_path from backup. Using the code sudo cp / etc / hosts /etc/hosts.backup you make a copy of the hosts file called "hosts.backup". If you make a mistake, move the misconfigured file with (for example) sudo mv / etc / hosts /etc/hosts.bad and restore the backup with sudo cp /etc/hosts.backup / etc / hosts.

Tips

  • The quotation marks at the beginning and end of the file path are only needed if there are spaces in the path.

Warnings

  • An error in root access can cause your Mac to be completely wiped or unusable. The risk is higher in 10.10 or older versions of OS X, or in 10.11 with SIP disabled. Keep your administrator password private at all times to prevent others from gaining root access.