I need to run a command with administrative privileges. Someone said I should run a command as root. How do I do this?
|
|
The main two possibilities are:
Running a command as rootsudoThis is the preferred method on most multi-user systems and on Ubuntu. If you don't know a separate root password, use this method. Sudo requires that you type your own password. (The purpose is to limit the damage if you leave your keyboard unattended and unlocked.) It is often configured to not ask again for a few minutes so you can run several Example:
If you need to run several commands as root, prefix each of them with
Instead of For more information, see the sudo website, or type suThe Example:
The command to run must be passed using the To run multiple commands as root, it is more convenient to start an interactive shell.
On some systems, you need to be in group number 0 (called Logging in as rootIf authorized, you can simply type Single User ModeSingle user mode, or run-level 1, also gives you root privileges. This is intended primarily for emergency maintenance situations where booting into a multi-user run-level is not possible. You can boot into single user mode by passing You can also get to single user mode by using the telinit command: On many systems booting into single user mode will give the user access to a root shell without prompting for a password. Other programsCalifeCalife lets you run commands as another user by typing your own password, if authorized. It is similar to the much more widespread sudo (see above). Calife is more light-weight than sudo but also less configurable. EmacsThanks to Tramp, you can run commands as root through In eshell, type You can also have OpOp lets you run commands as another user, including root. This not a full-blown tool to run arbitrary commands: you type SuperSuper lets you run commands as another user, including root. The command must have been allowed by the system administrator. Graphical frontendsA few other applications that use Gksu, Gksudo
and enter the root password, or type
and enter your password (if authorized to run KdeSu, KdeSudo
and enter the root password, or type
and enter your password (if authorized to run KtsussKtsuss (“keep the su simple, stupid”) is a graphical version of su. BeesuBeesu is a graphical front-end to the su command that has replaced Gksu in Red Hat-based operating systems. It has been developed mainly for RHEL and Fedora. See also Wikipedia. Running a graphical command as rootDepending on your system, The easiest solution is to use a graphical wrapper such as To achieve this manually, you'll at least need to make sure you retain the Editing a file as rootObviously, if you know how to run any command as root, you can run an editor. But that's not the most convenient or the safest method. Note: There are a few files that you should not edit directly:
sudoedit
EmacsYou can use Emacs's remote access mechanism (Tramp) to edit files as another user. Use the
|
|||||
|
|
Use
or
In either case, you will be prompted for the |
||||
|
|
|
Since the question was not Linux specific, here's how you achieve the same goal in Solaris 9+ (or Trusted Solaris 8): Solaris, since version 9, has included a suite of tools affectionately referred to as RBAC, or Role Based Access Control. The gist of RBAC is that through the granting of Authorizations and Rights, to Users and/or Role, or the granting of Roles to Users, you can create incredibly fine grained models for who can run what with which privileges. Essentially, you identify authorization in /etc/security/auth_attr, then grant them to users or roles in /etc/user_attr. You define profiles in /etc/security/prof_attr. You then associate commands with those profiles in /etc/security/exec_attr, followed by assigning those profiles to users in the /etc/user_attr file. Once those things are done, you actually run The nice thing about RBAC is that there are no additional privileges granted to the command itself, or the user, only to the combination of user + command. So it's safer than making a binary +s, or just using sudo to make a user be able to execute pretty much anything. (I know that you can lock down sudo, but in my experience most people don't) Another advantage of RBAC is that you can make root a role account, and assign that role to users who are able to become root with the 'su' command and the root password. The root user will also be able to log in in Single User Mode, which is better (in my opinion) than the Linux model where you can disable the root password Ben Rockwood has a great blog post on RBAC that can be read at Using RBAC on (Open)Solaris. |
||||
|
|
|
Or you can give some commands a superpower. I'm talking about special permissions in which commands are executed with the permission of owner. Get the path of command by P.S. - SUID and SGID bits should be given with care. They can make your system insecure. |
||||
|
|
|
use : su - root and passwd of root. |
||||
|
||||
We're looking for long answers that provide some explanation and context. Don't just give a one-line answer: please explain why you're recommending it as a solution. Answers that don't explain anything will be deleted. See Good Subjective, Bad Subjective for more information. |
||||
protected by Gilles May 1 '11 at 12:28
This question is protected to prevent "thanks!", "me too!", or spam answers by new users. To answer it, you must have earned at least 10 reputation on this site.
