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
Solved

what is the difference between su and su - ?

Posted on 2008-06-09
9
720 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 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
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
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 get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

809 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