LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-15-2016, 12:43 AM   #1
grigory
Member
 
Registered: Oct 2015
Posts: 133

Rep: Reputation: Disabled
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)?
 
Old 02-15-2016, 01:59 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,692

Rep: Reputation: 7275Reputation: 7275Reputation: 7275Reputation: 7275Reputation: 7275Reputation: 7275Reputation: 7275Reputation: 7275Reputation: 7275Reputation: 7275Reputation: 7275
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/
 
1 members found this post helpful.
Old 02-15-2016, 09:58 AM   #3
Blitzig
LQ Newbie
 
Registered: Feb 2016
Location: South Africa
Distribution: Fedora, RedHat, Centos7
Posts: 18

Rep: Reputation: 2
Hi,

I would suggest using sudo -i. It is a safe to keep track of who logged in as root on a system.
 
Old 02-15-2016, 06:35 PM   #4
grigory
Member
 
Registered: Oct 2015
Posts: 133

Original Poster
Rep: Reputation: Disabled
OK, thanks for your replies!
 
Old 02-16-2016, 12:44 AM   #5
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,692

Rep: Reputation: 7275Reputation: 7275Reputation: 7275Reputation: 7275Reputation: 7275Reputation: 7275Reputation: 7275Reputation: 7275Reputation: 7275Reputation: 7275Reputation: 7275
(if you really want to say thanks just click on yes)
 
1 members found this post helpful.
Old 02-16-2016, 07:50 AM   #6
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541

Rep: Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065
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.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
sudo: effective uid is not 0, is sudo installed setuid root? awladnas Linux - Newbie 10 08-30-2014 06:03 PM
Question about the sudo command, specifically how to have sudo act as if user is root slacker_ Linux - Newbie 17 09-22-2013 03:48 PM
LXer: The Ultimate Sudo FAQ — To Sudo Or Not To Sudo? LXer Syndicated Linux News 13 04-13-2013 01:36 AM
Unable to redirect all sudo messages to /var/log/sudo driftwood Linux - Server 2 10-18-2012 04:34 AM
Can't use sudo, only account that's not root is not a sudo'ers [Ubuntu 9.10] randyriver10 Linux - Desktop 1 01-09-2010 07:56 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:24 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration