How to Run Terminal As Admin on Mac


If you come from a Windows background and wondering how to run the CMD equivalent Terminal Console on Mac as administrator, well if elevated permissions are required for the default Mac user (who usually is an admin), you will be asked to enter your password.

Example let's say you are trying to remove a directory or install a new software package from the Terminal, you will be prompted for your password.

% rm -r mydir
password:

The root user and sudo command

In Windows we have the administrator user who can perform actions requiring elevated privileges. Along the same lines, a Unix-based operating system such as macOS or Linux, has the root user.

On Windows when you want to elevate the command prompt, you right-click on it and choose "Run as administrator", on the Mac Terminal you will make use of the sudo before any command you run.

Example:

    Here the dev user do not have the permission to do run cd command to access it as it belongs to the user c2ctech Desktop.

    dev@C2C-Tech-Mac c2ctech % cd Desktop
    cd: permission denied: Desktop

    Simply add sudo at the start of the command and you should be able to access it (provided you are part of the sudoers file)

    dev@C2C-Tech-Mac c2ctech % sudo cd Desktop

How to switch to root user

    One other way is to switch to the root user to get the admin privileges and you can run all commands using that user.

    Example:
    % Code2care@Mac % sudo su -
    Password:
    C2C-Tech-Mac:~ root# 
    Switch to root or admin user Mac Terminal

    Note: sudo su - command is not recommended for general tasks.

    Run the command whoami to know which user you are logged-in as.

    % whoami
    
    root

-

Facing issues? Have Questions? Post them here! I am happy to answer!


Author Info:

Rakesh (He/Him) is a seasoned developer with over 10 years of experience in web and app development, and a deep knowledge of operating systems. Author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail: rakesh@code2care.org

Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap