At times, depending on the operation being performed and the files or directories affected by it, we must execute commands as the superuser. In order to do this, the user account we’re using must be a member of a privileged group, recognized as the having superuser rights by the operating system. In Windows, this privileged group is the Administrators group; in Ubuntu, it’s the sudo group; in some other Unix-based systems (including OS X), it’s the wheel group.

Keep in mind that, even though a user account might be a member of one of these privileged groups, the commands run by that user are not executed with these elevated permissions by default. Instead, the default behavior is to run these commands with normal permissions. To access elevated permissions, we use the facilities outlined below.

Windows

Anytime we run a program from the Windows desktop, Start menu, or a File Explorer window, we can do so as an administrator (assuming the current user is a member of the Administrators group), by right-clicking on the executable program, and selecting Run as administrator from the context menu. This option is available when opening a Command Prompt window, as well as any other program; it’s not available when we launch a program indirectly—e.g. by double-clicking on a file used by that program.

Unlike Unix-based systems, Windows doesn’t provide a straightforward way to act as a superuser on a command-by-command basis in the command line interface.

Unix-based systems (including OS X, Linux Ubuntu, etc.)

In order to execute a command as a superuser from a terminal window, preface the command with sudo (“superuser do”). If this is the first time using sudo in the terminal session, or if a system-configured timeout period has elapsed since the last time sudo was invoked, the system will prompt you to re-enter your password, to confirm your identity and permissions..

Example

sudo mkdir -p /opt/android/sdk

As the superuser, creates the /opt/android/sdk directory.