Solved

what is the difference between su and su - ?

Posted on 2008-06-09
9
721 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 143

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
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 
LVL 6

Expert Comment

by:vojans
ID: 21748936
I can just confirm the above comments (angelIII)
0
 
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 Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Linux Hosting 16 81
error while installing php56 in redhat enterprise linux 20 78
Advice on ESXi 5.1 Health / Storage 1 49
regular expression help for sed command 5 43
If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

696 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