Questions tagged [sudo]

sudo is a tool which allows users to run commands as another user (usually the root user)

sudo allows users to run commands as another user. It is typically used to allow trusted users to run commands as root, without giving them root access, or to allow a user to run commands as another user. Both of these uses must be allowed by the root user.

886 questions
45
votes
9 answers

su not working on mac os x?

I get this: Macintosh:8.4 TAmoyal$ su Password: su: Sorry Macintosh:8.4 TAmoyal$ I typed in the password I use for sudo. Why won't this work? Thanks!
Tony
  • 4,213
  • 11
  • 35
  • 29
41
votes
3 answers

Running Ansible task as a specific user

I am trying to run a specific Ansible task as a different user than the one who is running the playbook. My .yml file looks like this: --- - hosts: staging_servers tasks: - name: check user remote_user: someusername shell:…
errata
  • 543
  • 1
  • 6
  • 9
40
votes
1 answer

Why can I update a file owned by root using sudo vi, but not append a line to it with sudo echo "Thing" >> file?

I would like to have script that is doing automated migrations of websites from another be able to append Includes to the /etc/httpd/conf.d/vhosts.conf file. However, when I try to use echo to put append a string to the end of the file I get this: $…
Nick Weavers
  • 501
  • 4
  • 8
35
votes
9 answers

How can I execute a bash function with sudo?

I have a bash function defined in a global bashrc, which requires root privileges to work. How can I run it with sudo, e.g. sudo myfunction. By default it gives an error: sudo: myfunction: command not found
Eugene Yarmash
  • 2,433
  • 5
  • 34
  • 54
33
votes
10 answers

Why su to root instead of logging in as root?

I've heard often that it is better to su to root rather than log in directly as the root user (and of course people also say that it's even better to use sudo). I've never really understood why one is better than the other(s), insight?
thepocketwade
  • 1,545
  • 5
  • 17
  • 27
32
votes
12 answers

How to pass alias through sudo

I have an alias that passes in some parameters to a tool that I use often. Sometimes I run as myself, sometimes under sudo. Unfortunately, of course, sudo doesn't recognise the alias. Does anyone have a hint on how to pass the alias through? In…
Tanktalus
  • 461
  • 1
  • 4
  • 11
31
votes
7 answers

Can a program tell it is being run under sudo?

I have a program that should behave differently if it is being run under "sudo". Is there a way it can find out if it was run under sudo? Update: Someone asked why would I want to do this. In this case, on a Mac using MacPorts there is output that…
TomOnTime
  • 7,945
  • 6
  • 32
  • 52
30
votes
1 answer

Changing the Sudo warning

The first time you try and sudo on a server you get the sudo warning; We trust you have received the usual lecture from the local System Administrator. It usually boils down to these three things: #1) Respect the privacy of others. #2) Think before…
Toby
  • 630
  • 2
  • 7
  • 17
30
votes
4 answers

vim re-edit as root

I often open a file in vim, make some changes and when it's time to save the file is read-only.. (owned by another user). I'm looking for tips on how I could re-open the file as root and keep my changes without first saving it to a temporary file…
rkthkr
  • 8,618
  • 28
  • 38
30
votes
7 answers

Why do I not have syntax highlighting when I sudo vi ?

I don't understand how to allow syntax highlighting in files I'm editing via vi when using sudo. When I sudo vi the terminal is only black & white of my terminal settings. In vi if I enter :syntax on nothing changes. When I vi
Scott Lundgren
  • 411
  • 1
  • 5
  • 7
28
votes
2 answers

How can I allow all users to run a given command via sudo?

I know how to create a command which a given user can execute via sudo. I have a given command I want to allow any user to be able to execute via sudo without entering a password. What would I put in my /etc/sudoers file in order to make that…
Josh
  • 9,190
  • 28
  • 80
  • 128
27
votes
4 answers

How do I list virsh networks without sudo?

I noticed a strange behavior on one machine using Debian that I can't reproduce on another machine running Ubuntu. When listing virsh networks as an ordinary user, it shows an empty list: ~$ virsh net-list --all Name State …
Arseni Mourzenko
  • 2,275
  • 5
  • 28
  • 41
27
votes
5 answers

What are the actual benefits of assigning sudo privileges to a user instead of using root?

I am fairly new to server administration, and I have seen a lot of sites recommending to assign sudo privileges to a user created by the root user and giving the root user an insanely long password for security enhancement. If the newly created user…
JM4
  • 1,144
  • 3
  • 18
  • 29
26
votes
2 answers

How does Amazon ec2-user get its sudo rights

I am looking for where the default Amazon AMI linux image sets up the privileges for the default ec2-user account. After logging in with this account I can use sudo successfully. Checking via the sudoers file, which I open by running visudo (with…
Johan
  • 447
  • 1
  • 5
  • 14
25
votes
2 answers

Why does password entering work in a piped sudo command?

If I do: sudo cat /etc/resolv.conf | less It will prompt me for the password, even though less (presumably) takes stdin. Over what fd's is the password prompt shown and how does it get the input back?
Karel
  • 639
  • 9
  • 16
1
2
3
59 60