PDA

View Full Version : root access, su and sudo




rhimbo
Aug 1, 2013, 01:55 AM
Hi folks,

Mac OS X 10.8.4 Mountain Lion, MacBook Pro....

I need enlightenment on how OS X is set up. I can't "su" at all. If I do "su" I am prompted for my password. I enter the same password that lets me "sudo" any command. I get the laconic message: "su: Sorry".

Normally, "sudo" lets me do anything I need to. For example, I can go into /opt and "touch" and "rm" files:

$ pwd
/opt
$ ls -ld
drwxr-xr-x@ 9 root admin 306 Jul 31 22:40 .
$
$ sudo touch foo
Password:
$ ls -lF
-rw-r--r-- 1 root admin 0 Jul 31 23:43 foo
-rw-r--r--@ 1 root admin 111363626 Jul 31 22:38 gcc-4.8.1.tar.gz
drwxr-xr-x@ 46 root wheel 1564 Jul 31 21:10 guile-2.0.9/
-rw-r--r--@ 1 root admin 33198080 Jul 31 21:01 guile-2.0.9.tar
$ sudo rm foo
$ ls -lF
-rw-r--r--@ 1 root admin 111363626 Jul 31 22:38 gcc-4.8.1.tar.gz
drwxr-xr-x@ 46 root wheel 1564 Jul 31 21:10 guile-2.0.9/
-rw-r--r--@ 1 root admin 33198080 Jul 31 21:01 guile-2.0.9.tar
$


But I'm getting permissions errors like the following on every single file in the tar distribution file when trying to install the GNU gcc compiler in /opt.


$ sudo gunzip -c gcc-4.8.1.tar.gz | tar xvf -
...

x gcc-4.8.1/libjava/classpath/lib/java/awt/MenuContainer.class: Failed to create dir 'gcc-4.8.1'Can't create 'gcc-4.8.1/libjava/classpath/lib/java/aw^
...


The extract works just fine if I go to some "scratch" directory that I create under my home directory. So the problem is not the integrity of the .tar.gz file. So I'm wondering if there is something I don't understand about the way Mac OS X handles permissions, "su" "sudo" and related things....

I've never really "developed" on Mac OS X at the shell/OS/etc... level as I've done on SunOS, Solaris, HP-UX, Linux, etc. in the past.

A related question is: is /opt the right place to install "additional" software, for example, if I want to install GNU software and don't want it to conflict with OS X utilities...?



robvas
Aug 1, 2013, 07:24 AM
You would never 'sudo' an untar/zip of source code. Normally you could untar/zip in a folder in your home directory, then run 'configure' and 'make' and then run the last step, 'make install' using sudo.

But what you really should be doing is using Homebrew (http://brew.sh/) to install software from source.

theluggage
Aug 1, 2013, 07:24 AM
$ sudo gunzip -c gcc-4.8.1.tar.gz | tar xvf -



What that command does is pass the command "gunzip -c gcc-4.8.1.tar.gz" to sudo, which runs it as root, and then pipes the output to "tar xvf -" which runs under your username. So tar doesn't get the privileges to create
the files.


$ sudo tar xvf gcc-4.8.1.tar.gz


...should do the trick - since, these days, tar understands .tar.gz files anyway.

In the more general case, if you want to use shell features (like pipes) in a sudo command use:


$ sudo -s "gunzip -c gcc-4.8.1.tar.gz | tar xvf -"


...which passes the whole command string to the shell.

If you like to live dangerously and crave an old-fangled "#" prompt, you can just type "sudo -s" to start something like a "root shell". Alternatively a quick google will tell you how to enable the real "root" on your mac.


A related question is: is /opt the right place to install "additional" software, for example, if I want to install GNU software and don't want it to conflict with OS X utilities...?


As good a place as any - but be aware that some other software uses it too - for example, MacPorts uses /opt/local. Or just make your own top-level directory. On a single-user personal computer it doesn't really matter... There are issues using "/home" though - anything you put there gets hidden by the NFS automounter unless you disable it.

If you want to use standard open source tools and applications, you might want to check out MacPorts (http://www.macports.org/) or Fink (http://fink.thetis.ig42.org/) which add Linux/BSD style package management and source/binary repositories to OS X.

rhimbo
Aug 1, 2013, 02:01 PM
Thanks guys. That's embarrassing. I forgot that pipes complicate the permissions issue. You can see it's been a long time since I've done shell work. Well, use it or lose it....

I'll also check out the references to Homebrew and macports.

Thanks again....