LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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, 01:43 AM   #1
grigory
Member
 
Registered: Oct 2015
Posts: 105

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, 02:59 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,124

Rep: Reputation: 2271Reputation: 2271Reputation: 2271Reputation: 2271Reputation: 2271Reputation: 2271Reputation: 2271Reputation: 2271Reputation: 2271Reputation: 2271Reputation: 2271
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, 10: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, 07:35 PM   #4
grigory
Member
 
Registered: Oct 2015
Posts: 105

Original Poster
Rep: Reputation: Disabled
OK, thanks for your replies!
 
Old 02-16-2016, 01:44 AM   #5
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,124

Rep: Reputation: 2271Reputation: 2271Reputation: 2271Reputation: 2271Reputation: 2271Reputation: 2271Reputation: 2271Reputation: 2271Reputation: 2271Reputation: 2271Reputation: 2271
(if you really want to say thanks just click on yes)
 
1 members found this post helpful.
Old 02-16-2016, 08: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,479

Rep: Reputation: 1020Reputation: 1020Reputation: 1020Reputation: 1020Reputation: 1020Reputation: 1020Reputation: 1020Reputation: 1020
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 07: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 04:48 PM
LXer: The Ultimate Sudo FAQ To Sudo Or Not To Sudo? LXer Syndicated Linux News 13 04-13-2013 02:36 AM
Unable to redirect all sudo messages to /var/log/sudo driftwood Linux - Server 2 10-18-2012 05: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 08:56 PM


All times are GMT -5. The time now is 02:20 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration