sudo - Execute a command with superuser privileges.

learn more… | top users | synonyms

80
votes
7answers
10k views

Which is the safest way to get root privileges: sudo, su or login?

I would like to have the root account in safety even if my unprivileged user is compromised. On Ubuntu you can only use sudo for "security reasons" by default. However I am not sure it is any safer ...
65
votes
5answers
19k views

Where did the “wheel” group get its name?

The wheel group on *nix computers typically refers to the group with some sort of root-like access. I've heard that on some *nixes it's the group of users with the right to run su, but on Linux that ...
56
votes
19answers
7k views

Root access that can't change root password?

We are having a little problem on a server. We want that some users should be able to do e.g. sudo and become root, but with the restriction that the user can't change root password. That is, a ...
43
votes
3answers
1k views

How do the internals of sudo work?

How does sudo work internally? How is it possible that it can become root without having the root password, unlike su? What syscalls, etc. are involved in the process? And why is however sudo does it ...
35
votes
4answers
10k views

How do I run a command as the system administrator (root)

I need to run a command with administrative privileges. Someone said I should run a command as root. How do I do this?
35
votes
5answers
3k views

Redirecting stdout to a file you don't have write permission on

When you attempt to modify a file without having write permissions on it, you get an error: > touch /tmp/foo && sudo chown root /tmp/foo > echo test > /tmp/foo zsh: permission ...
35
votes
2answers
2k views

Why do we need to use visudo instead of directly modifying the sudoers file?

I understand that if you want to modify who can use sudo and what they can do with it that you should use visudo. I know I'm not suppose to directly modify the sudoers file myself. What is it that ...
33
votes
4answers
2k views

Becoming root from inside Vim

Sometimes I start editing configuration files in /etc using Vim, but forget to use sudo to start Vim. The inevitable result then is that after finishing my edits I encounter the dreaded notice that I ...
23
votes
6answers
12k views

What is the need for 'fakeroot' command in linux

Why do we need fakeroot command at all? Can't we simply use the sudo or su commands? The man page says: fakeroot - run a command in an environment faking root privileges for file manipulation ...
21
votes
1answer
2k views

How to get root inside of vi? [duplicate]

Possible Duplicate: Becoming root from inside Vim It could happen to anyone. The admin types: vi /etc/resolv.conf as a regulare user. He edits the /etc/resolv.conf file, but when he ...
21
votes
7answers
811 views

Should scripts that require sudo fail if they don't have it, or use sudo and prompt?

I have a script which gives me fine-grained control over my backlight brightness and requires sudo to run. It's essentially this: backlight="/sys/class/backlight/acpi_video0/brightness" echo $1 | tee ...
21
votes
6answers
24k views

How to run a specific program as root without a password prompt?

I need to run something as sudo without a password, so I used visudo and added this to my sudoers file: MYUSERNAME ALL = NOPASSWD: /path/to/my/program Then I tried it out: $ sudo ...
20
votes
3answers
39k views

How to make Fedora user a sudoer?

I want to give a Fedora user sudo privileges. How do I do that?
19
votes
3answers
6k views

How is sudo intended to be used?

I've tried configuring sudo before, but I haven't had too much luck with it. How is it different from su -l -c "x"? It seems that via the configuration file, one can make it so a user can only have ...
18
votes
3answers
953 views

Where can I find documentation about the “sudo !!” command

I just learned that Linux has a sudo !! command which literally applies sudo to the last entered command. I had never heard about it. Is that a common control? Where can I find documentation about ...
17
votes
2answers
2k views

How does sudo remember you already entered root's password?

When using sudo on Linux, it asks for root password, but only the first time you run it. If you run another sudo command, it remember you already entered the password previously and doesn't ask for ...
15
votes
2answers
6k views

su vs sudo -s vs sudo bash

What is the difference between the following commands: su sudo -s sudo bash I know for su I need to know the root password, and for sudo I have to be in the sudoers file, but once executed what is ...
14
votes
3answers
1k views

If I sudo execute a Bash script file, will all commands inside the Bash script be executed as sudo as well?

I want to write an automated post-installation script in Bash (called post-install.sh, for instance). The script will automatically add and update repositories, install and update packages, edit ...
14
votes
4answers
871 views

How universal is sudo?

I was writing some instructions on how to install something (TeX-related - if you don't ask, I won't ruin your day by supplying more details) and used sudo to install system-wide. Someone commented ...
14
votes
4answers
433 views

What specific vulnerabilities am I creating by disabling the sudo password?

Here are some instructions on how to disable your sudo password. These carry the following warning If you disable the sudo password for your account, you will seriously compromise the security of ...
14
votes
2answers
690 views

How long is the password for executing a command with sudo cached?

If I run a command which requires root privileges with sudo, I will be asked to enter the current user's password. After that for a while, if I execute the same sort of commands with sudo, I won't be ...
13
votes
2answers
408 views

Is sudo not installed by default in Debian?

I was reading a guide to install some software and came reading until this shocking statement: sudo is not installed on Debian by default. Make sure your system is up-to-date and install it. As ...
13
votes
2answers
5k views

Is it possible to save as sudo from nano after you've forgotten to run as sudo?

A lot of the time I edit a file with nano, try to save and get a permission error because I forgot to run it as sudo. Is there some quick way I can become sudo without having to re-open and re-edit ...
12
votes
1answer
332 views

How to tell sudo to repeat lecture once?

I'm letting one of my coding buddies have root access to my Raspberry Pi, and as I was getting everything set up, I tested sudo as him. It gave me "the speech": We trust you have received the ...
11
votes
6answers
7k views

Is there a way to stop having to write 'sudo' for every little thing in Linux?

I'm a newbie when it comes to Linux. I do most of my development in a Windows environment. That said, I'm going to be doing a fair amount of PHP work shortly, and I'm interested in learning RoR, so ...
11
votes
3answers
3k views

Prompt for sudo password and programmatically elevate privilege in bash script?

I'm currently working on a bash script that installs and sets up various programs on a stock Linux system (currently, Ubuntu). Because it installs programs and copies a number of files to various ...
11
votes
1answer
446 views

How can I `alias sudo !!`?

I'm trying to set an alias for sudo !! in Bash. I tried alias sbb='sudo !!', but it interprets that as a literal !! and prints sudo: !!: command not found If I use double quotes, it substitutes ...
11
votes
2answers
4k views

What is the proper sudoers syntax to add a user?

According to the comments in /etc/sudoers (Fedora 13): ## Syntax: ## ## user MACHINE=COMMANDS ## ## The COMMANDS section may have other options added to it. My two related questions: What ...
11
votes
2answers
2k views

zsh wants to correct vim to .vim

I'm using zsh on Gentoo x64, and when I type sudo vim /path/to/file from my home folder, zsh asks: zsh: correct 'vim' to '.vim' [nyae]? I want to run vim not my .vim folder. How do I fix this? ...
11
votes
4answers
761 views

Can you give a user account multiple passwords?

I want to assign 2 passwords to a single account. What I want to know is 1) is this possible, and 2) what are the security implications of this? The reason I want to do this is because I'm currently ...
11
votes
2answers
1k views

How to safely pass variables to root-enabled scripts?

This question is totally general and not only applicable to my situation, but... I have a small busybox appliance where I want a non-root user to be able to execute a particular script with root ...
11
votes
3answers
9k views

`/etc/sudoers` — specify `env_keep` for one command only?

Is there any way to specify that sudo should preserve certain environment variables for specified commands only? For some purposes I'd like my $HOME env. variable preserved when I run certain ...
11
votes
3answers
4k views

sudo cannot open /etc/sudoers

sudo does not work. I have installed Arch Linux onto a USB key formatted with BTRFS. The output of sudo is: $ sudo sudo: unable to stat /etc/sudoers: Permission denied sudo: no valid sudoers sources ...
10
votes
4answers
6k views

Why doesn't “sudo su” in a shell script run the rest of the script as root?

A sample script can be as below: #!/bin/bash sudo su ls /root When using ./test.sh as the normal user, instead run ls as super user and exit, it switches to root; and when I logout, it executes ls ...
10
votes
1answer
832 views

What's the difference between sudo su - and sudo su --

When I am working on our RHEL machines, I use sudo su - to switch to being root. One day, a typo meant I typed sudo su -- instead - it seems to me that everything was the same as with a single hyphen, ...
9
votes
4answers
1k views

Sudoers for one day per week?

I have been volunteered by my boss to be the sysadmin for our production redhat server. He asked me to tighten the security to avoid mishaps like rm -f * that occured not long ago. Right now, we ...
9
votes
2answers
3k views

When do su and sudo use different passwords?

I am able to run anything using sudo; my password is accepted. But whenever I try to do su from a shell, it fails with: su: incorrect password What can the problem be?
9
votes
3answers
8k views

Does mount always require root privileges?

I was under the impression that any sort of call to mount requires root privileges. But recently I was told "You should instead create appropriate entries in /etc/fstab so that the filesystems can be ...
9
votes
4answers
5k views

What environment do I get with sudo?

When I run sudo, what exactly happens to my environment? When I run sudo command, it doesn't seem to see my or root's environment. For example, my path for both includes /usr/local/bin, but if I try ...
9
votes
2answers
117 views

How to automatically enter sudo's grace period upon CLI login?

What I would like to do is be able to login and sudo commands immediately without entering a password again. It is very redundant to type my password twice in a row when I need to login and run a ...
8
votes
5answers
9k views

Can a linux user change their password without knowing the current password?

I'm setting up a few ubuntu boxes, and using opscode's chef as a configuration tool. It would be fairly easy to install public keys for each user on each of these servers, and disable password ...
8
votes
2answers
8k views

using sudo on GUI applications

When I was using kubuntu, I could always open X applications with sudo, sudo kate for example. Now that I've switched to arch that doesn't work. I know I've always been told to use kdesu, but what ...
7
votes
4answers
1k views

sudo permission denied but su grants permission

this is the first occurrence where su was required for me. I read an article about changing the value in /sys/devices/virtual/backlight/acpi_video0/brightness to alter my laptop's screen brightness. ...
7
votes
3answers
755 views

which shell will sudo use to execute a shell script without the shebang line

My environment is Ubuntu 12.04 LTS, and the sudo version is 1.8.3p1. First I login as a normal user: $ whoami fin $ cat /etc/passwd | grep -i "root\|fin" root:x:0:0:root:/root:/bin/bash ...
7
votes
2answers
7k views

JAVA_HOME not set in script when run using sudo

I'm trying to run an install script that requires java to be installed and the JAVA_HOME environment variable to be set. I've set JAVA_HOME in /etc/profile and also in a file I've called java.sh in ...
7
votes
2answers
2k views

Forcing sudo to prompt for a password

If I do the following: sudo su - //enter password exit exit //login again straight away sudo su - The second invocation of sudo does not request a password because even though I have logged out ...
7
votes
6answers
934 views

Negatives/downsides of Ubuntu's no-root sudo setup

By default, Ubuntu does not create a root account that the user can login to. Instead users use sudo when they need to perform actions that require administrative access. Obviously, the people at ...
7
votes
3answers
8k views

How to set visudo to use a different editor than the default on Fedora?

Fedora 14 uses vi by default when one runs visudo. Is there a way to change this to something else?
7
votes
2answers
4k views

How do I get sudo -u $user to use the users env?

It seems when sudoing down that using sudo -u $user that the environment of root is still being used. How can I make sudo use the users environment? as a special note not all users that I will be ...
7
votes
2answers
8k views

How to disable requiretty for a single command in sudoers?

I want to disable requiretty so that I can sudo within scripts, but I'd rather only disable it for a single command rather than everything. Is that possible within the sudoers config?