Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 731
  • Last Modified:

what is the difference between su and su - ?

what is the difference between su and su - ?

and is there any other possibilities ?
0
jaisonshereen
Asked:
jaisonshereen
6 Solutions
 
ozoCommented:
$0 is different, which influences whether /etc/profile is executed

0
 
Guy Hengel [angelIII / a3]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
 
michofreihaCommented:
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
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
vojansCommented:
I can just confirm the above comments (angelIII)
0
 
torimarCommented:
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
 
omarfaridCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now