what is the difference between su and su - ?

what is the difference between su and su - ?

and is there any other possibilities ?
jaisonshereenAsked:
Who is Participating?
 
torimarConnect With a Mentor Commented:
It is advisable to use "su" only for minor  tasks (like gaining access to restricted files/folders etc.), and to stick to using "su -" in all other cases, because administrating a system from within a normal users environment may have unwanted consequences.

Although "su" defaults to switching to the root user, it may be used to change to any other user on the system, so:
su mary
su - mary
will prompt you for Mary's password and then login as that user.

There are more commandline options that may be used with "su", the most common of which is:
su -c 'command'
This will execute just the one specified command as root (or another user) and then immediately return to the original user who invoked "su".

Some systems may be set up to also support "sudo".
"sudo command" basically operates the same way as  "su -c" does, by executing just the one specified  command with root  privileges. On systems that do not come with a separate super user account (e.g. Ubuntu and derivatives) which one could switch to, "sudo" is the main means of administration.
Note: The password you are prompted for when invoking "sudo" is your own!

Read more here:
http://www.gnu.org/software/coreutils/manual/html_node/su-invocation.html
http://www.linfo.org/su.html
http://linux.about.com/od/commands/l/blcmdl8_sudo.htm
0
 
ozoConnect With a Mentor Commented:
$0 is different, which influences whether /etc/profile is executed

0
 
Guy Hengel [angelIII / a3]Connect With a Mentor Billing EngineerCommented:
"su" and "su root" is the same, switch user content to root user.
the "-" is to start the complete shell environment of that user
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
michofreihaConnect With a Mentor Commented:
Hi !!

su gives you root permissions but it does not change the PATH variable and current working directory. so you can't execute files in /usr/sbin folder.

su - changes the PATH too... and root's home becomes your current working directory. you become proper root and can execute all commands.

$ su
$ echo $PATH
$ pwd
0
 
vojansCommented:
I can just confirm the above comments (angelIII)
0
 
omarfaridConnect With a Mentor Commented:
su is used to switch from user to another. For certain tasks and situations you want to have the full env. set which means reading /etc/profile, ~.profile (this is for sh and ksh users. It could be different files for csh and bash), change the current working dir.
0
 
ahoffmannCommented:
RTFM, shameless stolen from (Linux') man su

       -, -l, --login
            Provide an environment similar to what the user would expect had the user logged
             in directly
0
 
jaisonshereenAuthor Commented:
Cool
0
All Courses

From novice to tech pro — start learning today.