.profile .bash_profile not sourced when sudo su

Discussion in 'macOS' started by Tex-Twil, Dec 18, 2008.

  1. Tex-Twil macrumors 68020

    Tex-Twil

    Joined:
    May 28, 2008
    Location:
    Europe
    #1
    Hi,
    I have a .profile file for my user and it is sourced correctly when I ssh to my OSX (10.5) When I do

    Code:
    sudo su
    
    to become root, the .profile file on the HOME dir (/var/root) is not sourced ...

    I tried also with .bash_profile and .bashrc but it is never sourced. Any ideas ?

    Thanks,
    Tex
     
  2. Tex-Twil thread starter macrumors 68020

    Tex-Twil

    Joined:
    May 28, 2008
    Location:
    Europe
    #2
    hmm, I've just realized that the root account doesn't use bash but sh as shell.

    Code:
    jan@me ~ $ echo $SHELL
    /bin/bash
    jan@me ~ $ sudo su
    root@me ~ # echo $SHELL
    /bin/sh
    
     
  3. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #3
    su switches user, but does not re-login. If you want to create a login environment then use "su -"
     
  4. Tex-Twil thread starter macrumors 68020

    Tex-Twil

    Joined:
    May 28, 2008
    Location:
    Europe
    #4
    I tried this before but it doesn't accept my password.
     
  5. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #5
    Hmm, possibly because you can't login as root therefore you can't create a login environment as root either?
     
  6. Tex-Twil thread starter macrumors 68020

    Tex-Twil

    Joined:
    May 28, 2008
    Location:
    Europe
    #6
    Well I only have my "user"account on my OSX and I havent created anything else. I thought that OSX works in the same was as Ubuntu linux distributions i.e. there is no login for root and if we want to be root, we have to "sudo su".
     
  7. J the Ninja macrumors 68000

    Joined:
    Jul 14, 2008
    #7
    By default, it does. If you open up Directory Utility, and go to the edit menu, you'll see an option called "Enable root user". The first time you click this, it will prompt you to make a root password. (Note: the "Enable root user" option will be disabled until you unlock the window, the same way you would a preference pane).

    With this one, you'll also be able to directly log in as root through the GUI, by typing in the username "root" and the root password.
     
  8. jmxp69 macrumors 6502

    Joined:
    Dec 10, 2008
    #8
    As a non-root admin you can also do this:

    sudo passwd root
    Enter your password
    Create root password
    Verify root password

    After that, just: su - and that will load .profile from /var/root
     

    Attached Files:

  9. Tex-Twil thread starter macrumors 68020

    Tex-Twil

    Joined:
    May 28, 2008
    Location:
    Europe

Share This Page