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
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 -
Note: sudo su - command is not recommended for general tasks.
Run the command whoami to know which user you are logged-in as.
Facing issues? Have Questions? Post them here! I am happy to answer!
- How to Display Analog Clock on Mac Menu Bar
- Shutdown Mac Terminal Command
- How to know the Serial Number of MacBook on macOS Ventura 13.0
- macOS: Remove Desktop or Documents Folder from iCloud Drive Syncing
- [fix] How to Show file extensions on all files on Mac
- How to install Zoom Add-in to Outlook (Mac)
- How to turn off Stage Manager - macOS Ventura
- Fix - Xode - Internal logic error: Connection was invalidated
- How to do calculations in Mac Terminal
- How to delete a Page in Microsoft Word File on Mac (macOS)
- How to Refresh Mac Desktop
- How to install Java on macOS [Big Sur]
- How to Disable Mac Terminal Bell Sound
- Installing MongoDB on Linux/Unix/macOS/Ubuntu
- How to Uninstall Brew on Mac
- Find your macOS version
- Change TextEdit File Encoding
- AppleScript Example with TextEdit
- How to install homebrew (brew) on M1 Mac
- How to Find File and Directory Size in Mac Terminal
- How to open new tab in Sublime Text Editor [macOS]
- How to list all users in Mac Terminal
- Turn off Auto-Capitalization on macOS Ventura 13
- How to check Command Line Tools Version [Updated for Ventura]
- Change Current User Password using Mac Terminal Command
- How to find Java HOME in Mac Terminal - MacOS
- How to Validate String Date Format in Java - Java
- How to Install Windows Subsystem for Linux (WSL) on Windows 11 (22H2) - Windows-11
- TextEdit Clear Formatting when Pasting Text - MacOS
- How to Select Two Separate Columns in Excel on Mac - Microsoft
- [fix] zsh: command not found: telnet on Mac - MacOS
- How to Find and View Stored Wi-Fi Password on iPhone - iOS
- How to Insert an Inverted Question Mark on Mac ¿ - MacOS