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

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
up vote 8 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
"sudo, sudoedit — execute a command as another user" – David Schwartz Feb 26 '15 at 10:20

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

You can think of the 'su' in sudo as "switch user". If you don't say which user to run as, it will default to root, the superuser, also associated with su.

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

You must log in to answer this question.

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