Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

1 Answer 1

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;
fi

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

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.