What is the difference between the sudo and su command? Why does OS X handle these different than Linux?

  • 2
    If anything, Linux would handle them differently than OS X. OS X is certified Unix, which means it conforms to a certain standard of behavior. Linux is Unix-like, but is not certified Unix and doesn't necessarily conform to the Unix standard. So if there are differences (other than the root password issue noted in Aaron Lake's answer), they are non-conformance on the part of the implementers of the particular Linux distribution in question.
    – alesplin
    May 2, 2012 at 5:13

1 Answer 1


OS X handles sudo and su identically to Linux.

sudo is a command that, without any additional options, will run a command as root. For example:

% touch /newfile
touch: /newfile: Permission denied
% ls -l /newfile
ls: /newfile: No such file or directory
% sudo touch /newfile
% ls -l /newfile 
-rw-r--r--  1 root  wheel  0 Apr 27 11:45 /newfile

su on the other hand, will switch the current user to root (again without any extra commands). In the example below, I have to run sudo su, since I don't know the root password for my system:

% whoami
% sudo su
$ whoami

The key difference between sudo and su is sudo runs a command as root, whereas su makes you root. Much like other command line utilities there are a number of alternative ways to use both sudo and su, if you're interested you can always run man <command> eg. man sudo to get more information.

  • 5
    In simple language terms sudo can be though of as super user and do. As an additional point, on OS X, once you have successfully authenticated you may then use sudo without a password for a short time (5 minutes by default, unless overridden in sudoers) after which you will have to type the password again.
    – binarybob
    Apr 27, 2012 at 18:26
  • 1
    the 'without additional options' is a pretty significant qualifier ... they'll both let you become users other than root ... eg, sudo su -lm _www will let you have as shell as if the webserver user (by running the command as root, as it doesn't have a valid password)
    – Joe
    Apr 27, 2012 at 19:19
  • 2
    @Joe, I considered adding that information but omitted for brevity. As you describe, sudo is quite a robust utility and covering even basic functionality here would ultimately confuse or overwhelm the target audience looking for a differentiation between sudo and su.
    – Aaron Lake
    Apr 27, 2012 at 19:21
  • "The key difference between sudo and su is sudo runs a command as root, whereas su makes you root" - false, sudo -s runs shell ("makes you root"), and su -c command runs command as root. Apr 27, 2012 at 20:33
  • 2
    Again for brevity's sake I omitted the many alternative methods of using sudo. Also, you can't do su -c command by default on OS X, since you don't know root's password. You can, however sudo su, change the password, then su -c command. I feel that the question was answered, and there wasn't a need to dive deeper in to alternate uses of sudo and su. However I'll update the post for the curious folks.
    – Aaron Lake
    Apr 27, 2012 at 20:37

You must log in to answer this question.

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