Solved

what is the difference between su and su - ?

Posted on 2008-06-09
9
717 Views
Last Modified: 2010-04-21
what is the difference between su and su - ?

and is there any other possibilities ?
0
Comment
Question by:jaisonshereen
9 Comments
 
LVL 84

Assisted Solution

by:ozo
ozo earned 50 total points
ID: 21748813
$0 is different, which influences whether /etc/profile is executed

0
 
LVL 142

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 50 total points
ID: 21748815
"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
 
LVL 9

Assisted Solution

by:michofreiha
michofreiha earned 50 total points
ID: 21748828
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
 
LVL 6

Expert Comment

by:vojans
ID: 21748936
I can just confirm the above comments (angelIII)
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 12

Assisted Solution

by:ibu1
ibu1 earned 100 total points
ID: 21748999
0
 
LVL 35

Accepted Solution

by:
torimar earned 200 total points
ID: 21749106
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
 
LVL 40

Assisted Solution

by:omarfarid
omarfarid earned 50 total points
ID: 21749904
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
 
LVL 51

Expert Comment

by:ahoffmann
ID: 21755163
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
 

Author Closing Comment

by:jaisonshereen
ID: 31465635
Cool
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now