Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I was writing a simple script that had to be run as 'user'. I run it half the time as myself and half the time when su as the user, so to save time I wrote it as

sudo -u user ./doStuff

but this doesn't work correctly because when I am logged in as user this command fails because I don't have sudo permissions to do... everything I could already do.

My question is, is there a reason for not defaulting every user as having permission to sudo as themselves; for ease of scripts such as this? is there some sort of security whole I'm missing that would be created by this, or is it just not something anyone bothered to implement?

second, more out of curiosity then a real need, how would one modify the /etc/sudoers file to make it so every user could, by default, sudo -u as themselves? I know my original script could have been written by using a check who the user is, but I'm going to write lots of scripts like that one for convenience while testing and I want to cut out the extra steps that I could forget to add in some future script.

share|improve this question
As to why sudo is required, OS X and Windows requires similar actions, its basically a way to verify the user is actually the user. – Ramhound Jul 3 '13 at 18:36
up vote 1 down vote accepted

Using sudo to log in as your current user is inelegant to say the least. A better way would be to simply test if you are logged in as user in your script and act accordingly. For example, if this is a bash script do

if [[ $USER != "user" ]]; then
   su user;

Anyway, if you really want to do this, use su instead:

$ whoami
$ su terdon
$ whoami
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .