Learn Difference Between “su” and “su -” Commands in Linux

In an earlier article, we have explained to you the difference between sudo and su commands in Linux. These are two important commands used to implement security in Linux, in regards to user management policy and user permissions.

The su command is used to switch to another user, in other words change user ID during a normal login session (that is why it is sometimes referred to as switch (-) user by a number of Linux users). If executed without a username, for example su -, it will login as root user by default.

A common challenge faced by new Linux users is understanding the difference between “su” and “su -“. This article will help you briefly understand the difference between “su” and “su -“ in Linux systems.

Usually, to become another user or login to other user, you can invoke the following command, then you will be prompted for the password of the user you’re switching to.

$ su tecmint
Switch Users in Linux
Switch Users in Linux

Considering the scenario in the screenshot above, it is significant to note that the user tecmint keeps the environment from user aaronkilik’s original login session, the current working directory and the path to executable files also remain the same.

As a result, when user tecmint tries to list the working directory (which is still user aaronkilik’s working directory), the error: “ls: cannot open directory .: Permission denied” is displayed.

But at the end, user tecmint can list his home directory after running cd command without any options.

Secondly, when you invoke su with a -, or -l or --login flags, it offers you a login interface similar to when you are logging on normally. All the commands below are equivalent to each other.

$ su - tecmint
OR
$ su  -l tecmint
OR
$ su --login tecmint

In this case, the user tecmint is provided his own default login environment, including path to executable files; he also lands into his default home directory.

Login as Different User
Login as Different User

Importantly, when you run su without a username, you will automatically become the superuser. You will be given root’s default environment, including path to executable files changes. You will also land into root’s home directory:

$ su

Also check out: How to Show Asterisks While Typing Sudo Password in Linux

We hope you find this article informative. You can ask any questions or share your thoughts via the comment section below.

If you read this far, tweet to the author to show them you care. Tweet a thanks
Aaron Kili
Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

20 thoughts on “Learn Difference Between “su” and “su -” Commands in Linux”

  1. You didn’t answer the question of the title of the article and you gave erroneous information (for my Debian installation).

    su – will ask for the root password and switch me to root user and give me the root environment, pwd shows /root

    su (without the dash) will ask for the root password and switch me to root user and leave me in the original user’s environment, pwd shows /home/originaluser

    Reply
  2. The article does NOT answer the question posed: What is the difference between “su” and “su –“?

    E.g., on Sparky Linux, if you switch to root in a terminal by “su” then the root password, you will NOT get access to “swaplabel“. One has to switch to root as “su –” and the root password NOT simply “su” in order to be accorded all root paths.

    The question was simple, so’s my answer.

    Reply
  3. From the manpage of ‘su‘ (on opensuse).

    #####8<#####
    NAME
    su – run a command with substitute user and group ID

    SYNOPSIS
    su [options] [-] [user [argument…]]

    DESCRIPTION
    su allows to run commands with a substitute user and group ID.

    When called without arguments, su defaults to running an interactive shell as root.

    For backward compatibility, su defaults to not change the current directory and to only set the environment variables HOME and SHELL (plus USER and LOGNAME if the target user is not root). It is recommended to always use the
    –login option (instead of its shortcut -) to avoid side effects caused by mixing environments.
    #####8<#####

    So, the su means 'switch user', with the default user being the "top" administrative user, as Aaron explains

    Reply
    • @Jonix

      We do not have to copy and paste the definition from man pages in our articles, we simply explain in terms users can easily understand and relate with. Of course, you can always find more information in man pages.

      And different distros offer different command/program descriptions. For example on Ubuntu or Linux Mint, the man page says:
      “NAME su – change user ID or become superuser”

      Thanks for sharing your thoughts with us.

      Reply
  4. su without a username and you become the root user not super user. There is no such thing as super user, just root user. That super user crap started years ago and is still perpetuated. sheesh

    Reply
    • @Marshall

      I guess we have fallen victims of using superuser to mean root user. However, the two words “root” and “superuser” are used interchangeably in relation to Unix/Linux operating systems today. According to Wikipedia, “superuser is a special user account used for system administration. Depending on the operating system (OS), the actual name of this account might be root, administrator, admin or supervisor.”

      Thanks for sharing your concern with us.

      Reply
      • During the install, some distros ask if the first user created is to be the administrator. If you say YES, that user becomes the superuser but he DOES NOT become the root.

        Reply
        • @dragonmouth

          Yes, this is correct. But in the article, we are referring to root as the superuser(vice versa), who has absolute permission to perform any kind of task on a Linux system, without using sudo command.

          Thanks for pointing this out.

          Reply
  5. One interesting thing that can be done with sudo is starting a “longtime” shell by issuing ‘sudo bash‘ ; instead of issuing root-claimimg commands one at a time (do remember to logout of this subshell when finished, to avoid stupid things done with the power-of-root)

    Reply
    • @Phil

      When a user invokes sudo, then that user gains root privileges. But the cases explained above( for su and su -) will apply but to the root user.

      Reply

Got something to say? Join the discussion.

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.