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.

When I run '# sudo touch newfile' my expectation was that the file would be owned by me, not by root, as my understanding of sudo is that it is giving me, the user, root priviledges but does not actually switch the user.

Do I have a fundamental misunderstanding of what sudo is about?

share|improve this question

4 Answers 4

up vote 6 down vote accepted

When you use sudo, you run a program as the superuser (root), so files that are created are created as the superuser.

share|improve this answer

The 'su' in sudo means "set userid". If you don't say which user to run as, it will default to root.

sudo -u yourself touch newfile if you want the file to be owned by yourself.

Your assumption that sudo doesn't change the userid is correct in the perspective of the rest of your session. Think of it as su + touch newfile + exit. So, in your shell you "remain" yourself, but sudo executes your command in a new process with another effective userid.

share|improve this answer
1  
The 'su' in 'sudo' means "Super User" (sudo = Super User Do), not "set userid". The command 'su' means 'Switch User'. –  Mistiry Jul 9 '10 at 15:59

What mipadi said, which you can demonstrate by comparing the output of these two 'whoami' ("who am I?") commands:

$ sudo whoami
$ whoami

share|improve this answer

sudo (name comes from su "do" or super user "do") allows you to run command as root. It does not give your user different privileges. Therefore, when you run #sudo touch newfile it is user root that executed command touch newfileand that is why newfile is owned by user root.

More information at Sudo page.

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.