Questions tagged [sudo]

sudo - Execute a command with superuser privileges.

Sudo (superuser do) allows a system administrator to delegate authority to give certain users (or groups of users) the ability to run some (or all) commands as root or another user while providing an audit trail of the commands and their arguments.

The configuration file for sudo is /etc/sudoers (as well as /etc/sudoers.d/* in recent versions). Best practice is to use the visudo command to edit /etc/sudoers. This utility safeguards the user by locking the file (preventing simultaneous edits) and checking for syntax errors before saving the file. It can also be used to edit files in the /etc/sudoers.d directory, by using its -f, --file= option e.g.,

sudo visudo -f /etc/sudoers.d/customisations

Further reading

2409 questions
269
votes
8 answers

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 seems to be anyone (although you need the root…
Michael Mrozek
  • 91,316
  • 38
  • 238
  • 232
237
votes
15 answers

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 /path/to/my/program [sudo] password for MYUSERNAME: Why does it ask…
LanceBaynes
  • 39,295
  • 97
  • 250
  • 349
237
votes
8 answers

Why do I need a tty to run sudo if I can sudo without a password?

I have configured sudo to run without a password, but when I try to ssh 'sudo Foo', I still get the error message sudo: sorry, you must have a tty to run sudo. Why does this happen and how can I work around it?
merlin2011
  • 3,855
  • 5
  • 27
  • 36
201
votes
9 answers

How to make `sudo` preserve $PATH?

I have a program that is installed in a custom directory under /opt. To make it easier to run it, I edited my bashrc to add said directory to my path: export PATH=$PATH:/opt/godi/bin:/opt/godi/sbin This works fine if I want to run the program…
hugomg
  • 5,543
  • 4
  • 35
  • 53
163
votes
4 answers

-bash: sudo: command not found

I am trying to deploy django app. When I print apt-get update I see W: Unable to read /etc/apt/apt.conf.d/ - DirectoryExists (13: Permission denied) W: Unable to read /etc/apt/sources.list.d/ - DirectoryExists (13: Permission denied) W: Unable to…
user2950593
  • 1,797
  • 2
  • 13
  • 9
149
votes
10 answers

Username is not in the sudoers file. This incident will be reported

I am running Ubuntu 12.04 on my laptop using VMware Player. I am not sure why but I have an account called "User Account" in addition to my account that I usually login to use Ubuntu. Well that was just a side comment but basically all I am trying…
fsolano94
  • 1,627
  • 2
  • 11
  • 4
139
votes
8 answers

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 About.com says: Gives a fake root environment. This…
gkt
  • 1,563
  • 2
  • 11
  • 7
137
votes
7 answers

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 denied: /tmp/foo Sudoing doesn't help, because it runs the command as…
Michael Mrozek
  • 91,316
  • 38
  • 238
  • 232
133
votes
8 answers

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 than just using login on a text-mode console. There…
stribika
  • 5,374
  • 5
  • 30
  • 35
123
votes
6 answers

How to run a command that involves redirecting or piping with sudo?

I am trying to follow what I assume is best practices of using sudo instead of root account. I am running a simple concat file operation such as: sudo echo 'clock_hctosys="YES"' >> /etc/conf.d/hwclock This fails as to the right of the ">>" it is…
DarkSheep
  • 1,796
  • 3
  • 14
  • 18
122
votes
3 answers

su vs sudo -s vs sudo -i vs sudo bash

What is the difference between the following commands: su sudo -s sudo -i 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 difference? I know there is a difference…
TJ Shah
  • 1,711
  • 3
  • 13
  • 13
115
votes
2 answers

su options - running command as another user

I was wondering how to run a command as another user from a script. I have the script's owner set as root. I also have the following command being run within the script to run the command as the hudson user: su -c command hudson Is this the correct…
myusuf3
  • 1,385
  • 3
  • 9
  • 9
113
votes
6 answers

How could we allow non-root users to control a systemd service?

With sysvinit, a sudoers entry like this would suffice: %webteam cms051=/sbin/service httpd * This would allow for commands such as: sudo service httpd status sudo service httpd restart Now, with systemd, the service name is the final argument.…
Belmin Fernandez
  • 9,347
  • 15
  • 46
  • 50
100
votes
2 answers

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 supposed to directly modify the /etc/sudoers file myself. What is it that visudo does that directly modifying the file…
Dason
  • 1,102
  • 2
  • 8
  • 13
98
votes
11 answers

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

I'm going to be doing a fair amount of PHP work shortly, and I'm interested in learning RoR, so I installed Linux Mint 12 in my VirtualBox. The most frustrating aspect of the switch, so far, has been dealing with Linux permissions. It seems like I…
Major Productions
  • 1,105
  • 1
  • 8
  • 12
1
2 3
99 100