I'm logged in as a user "foo" which is part of group "wheel" after adding via pw group mod wheel -m foo. Where is the difference between:

login: root


su root

1 Answer 1


The use of the login command will ensure that a new login shell (one that changes the environment variable PATH, USER and many others) is started.

The command su root starts a shell but does not change the environment. That could cause some unexpected problems.

A su -login root or su -l root or su - root or simply su - will start a login root shell.

A sudo su - will start a login root shell but using the user password (not root password).

This answer has some additional information

  • Can I run only one application as root like sudo vi file does for Linux?
    – Hölderlin
    Jun 23, 2017 at 12:47
  • 1
    @Hölderlin It is a bad practice to start graphical programs (GUIs) as root like vim. But if you actually mean vi in the command line, no, there is no set limit. You can start as many as you wish. Even with only one console if you end each command with &: sudo vi file1 & (send the command to background), then just press enter (if needed) to get the console prompt again and start sudo vi file2 &, repeat as many times as you may need.
    – user232326
    Jun 23, 2017 at 12:52
  • Sry my question was not clear enough. What I mean is, if su in FreeBSD compare to sudo under Linux or how can I act as root without root login, e.g. for just one application like sudo vi file?
    – Hölderlin
    Jun 23, 2017 at 13:00
  • The command su means "switch user", it allows an user to change to some other (many times root) with su -l user. The command sudo should be understood as "switch user and do". To execute su - you need the password of root, to execute sudo su - (which has exactly the same final effect) you need the user password (and the user has to be included in the sudoers file). Both su and sudo are available in most Unix and Linux OS. But as I have just explained they have different use cases and are not equivalent, similar, but not equivalent.
    – user232326
    Jun 23, 2017 at 13:08
  • @Hölderlin When you say: without root login, do you mean starting a new desktop (X server) and login? That would not be accurate as any time you use the root password or sudo provides its equivalent you are actually login as root. Be it for one shell, one command, or a whole X server session (the whole time your desktop is active). Am I answering your question? Or am I still not getting it right?
    – user232326
    Jun 23, 2017 at 13:12

You must log in to answer this question.

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