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?


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

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


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.


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.

  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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