Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»General Articles»Difference Between `su` and `su -` Commands in Linux

    Difference Between `su` and `su -` Commands in Linux

    By RahulJanuary 1, 20232 Mins Read

    In Linux, the `su` command allows a user to switch to a different user account. The `su` command can be followed by the name of the user to switch to, and will prompt the user for the password of the user they are trying to switch to.

    Advertisement

    The `su` command has a number of options that can be used to modify its behavior. One of these options is `-`, which stands for “login shell”. When the `-` option is used with the `su` command, it causes the su command to run a login shell for the specified user. This means that the user’s environment variables and profile scripts will be sourced as if they had logged in to the system normally.

    For example, to switch to the root user and run a login shell, you would use the following command:

    su - root 
    

    Check for the system environment after switching to the root user.

    `su - root` command example
    `su – root` command example

    On the other hand, if you omit the `-` option and just use the `su` command by itself, it will switch to the specified user without running a login shell. This means that the user’s environment variables and profile scripts will not be sourced, and the user will be in the same environment as before they switched users.

    For example, to switch to the root user without running a login shell, you would use the following command:

    su root 
    

    See the system environment after switching to the root user.

    `su root` command example
    `su root` command example

    In summary, the difference between `su` and `su -` is that `su` switches to the specified user without running a login shell, while `su -` switches to the specified user and runs a login shell. It’s important to understand this difference, as it can affect the environment in which you are working when switching to a different user account.

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    sleep Command in Linux with Examples

    20 Basic Linux Commands for the Beginners (Recommended)

    tail Command in Linux with Examples

    Add A Comment

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • Test Your Internet Speed from the Linux Terminal
    • 11 Practical Example of cat Command in Linux
    • sleep Command in Linux with Examples
    • 20 Basic Linux Commands for the Beginners (Recommended)
    • tail Command in Linux with Examples
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.