LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Sudo su vs. sudo su - in Ubuntu 14.04 (https://www.linuxquestions.org/questions/linux-newbie-8/sudo-su-vs-sudo-su-in-ubuntu-14-04-a-4175572286/)

grigory 02-15-2016 12:43 AM

Sudo su vs. sudo su - in Ubuntu 14.04
 
Hello!

I've always been using either sudo or sudo su. And today I found out that there's also a sudo su - option. That it changes the pwd and sets the root's environment too. In regards to the latter, would it make any difference if I'm trying to do under root:
a) delete files;
b) change attributes of files;
c) install and uninstall applications;
d) edit config files;
e) delete root's trash
OR... no matter what, I should always add a hyphen after "su" and not adding it is just a bad habit (as some say)?

pan64 02-15-2016 01:59 AM

I suggest you to read the man page of sudo and su.
You will see: sudo — execute a command as another user, and su - change user ID or become superuser
sudo su -
are the two commands combined together and usually it is not required. One wanted to use either sudo or su.
https://kb.iu.edu/d/amyi
http://askubuntu.com/questions/37619...-which-is-used
http://www.howtogeek.com/111479/htg-...tween-sudo-su/

Blitzig 02-15-2016 09:58 AM

Hi,

I would suggest using sudo -i. It is a safe to keep track of who logged in as root on a system.

grigory 02-15-2016 06:35 PM

OK, thanks for your replies!

pan64 02-16-2016 12:44 AM

(if you really want to say thanks just click on yes)

tronayne 02-16-2016 07:50 AM

The su utility allows you to become root or any other user (you will be required to enter the root or other user password).

su, by itself, is extremely limited in terms of PATH and other environment settings:
Code:

fubar-trona-/home/trona: su
Password:
fubar-root-/home/trona: print ${PATH}
/usr/local/sbin:/usr/local/bin:/sbin:/usr/sbin:/bin:/usr/bin

It's for quick and dirty "super user" work such as changing permissions or executing commands that otherwise you as a normal user would not be able to do.

[I]su -/I], however, is "as if you logged in as the user on the console." Note the difference:
Code:

fubar-trona-/home/trona: su -
Password:

As of next week, passwords will be entered in Morse code.

fubar-root-/root: print ${PATH}
.:/root/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/usr/games:/opt/GMT/bin:/usr/lib64/java/bin:/usr/lib64/java/jre/bin:/usr/lib64/kde4/libexec:/usr/lib64/qt/bin:/usr/share/texmf/bin

The dash gives you the full environment settings of the user, be it root or any other user.

sudo is a sort of one-shot utility; you run something once and that's that (pretty much). Either su or su - will stay in effect until you exit. Doesn't make much sense to use them in series.

Hope this helps some.


All times are GMT -5. The time now is 10:00 PM.