2411

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

A general difficulty encountered by newbie Linux users is knowing the difference between “su” and “su -“.

This section will help you to understand the distinction between “su” and “su -“ in Linux systems.

The su command is used to switch to another user, It is also referred to as switch (-) user. If su - is executed without a username, it will login as root user by default.

Now let's understand the difference between “su” and “su -”

If we switch to another user using su, it can be noted that the environment is kept the same as before switching. For an instance refer the below example.

[user1@int Desktop]

$ su user2

Password:

[user2@int Desktop]

$

It can be noted from the above Commandline that when su is executed from the environment(desktop) of user1 it keeps it the same. As a result, when user2 tries to execute another command (touch test) at this working directory (which is still user2 working directory), you will receive this error : touch: cannot touch `test': Permission denied. But, it should be noted that the user2 can execute after moving into user2's directory.

Now If we excute su - (i.e su with -), it will login into user2's default login environment, and into the users home directory, where the user can run any supported commands freely.


[user1@int Desktop]

$ su - user2

Password:

[user2@int ~]$

Leave a Reply