Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm trying to set up a sane/usable environment in a barebones OpenSolaris-derivative (OmniOS, a distribution of Illumos/OpenIndiana). I have all the plumbing code I need in .profile, .inputrc, and .bashrc files ready to promote to system-wide use, but no system-wide scripts are being sourced for non-login shells. Bash attempts to load the user's .bashrc file on su, but $HOME (and any other environment variables) remains configured for the previous user.

Output from a direct (SSH) login:

login as: myuser
Using keyboard-interactive authentication.
Password:
/etc/profile run
myuser's .bashrc run
myuser's .profile run
myuser@Helios:~$ echo ~
/home/myuser
myuser@Helios:~$

Output switching user:

root@Helios:/etc# su myuser
bash: /root/.bashrc: Permission denied
bash-4.2$ id
uid=1001(myuser) gid=100(users) groups=100(users),27(sudo)
bash-4.2$ echo ~
/root
bash-4.2$

Note in particular the attempt to source root's .bashrc instead of myuser's .bashrc.

su (without additional arguments) has always worked seamlessly in Ubuntu, Fedora, etc. and I intend to replicate that experience, but what can I do when no system-wide scripts run and the user's scripts cannot be found? I'm inclined to blame OmniOS's version of bash and/or su for missing something, but what exactly is the correct behavior? Can I configure/access/script additional plumbing somewhere which addresses the failure to update $HOME and other envvars?

Further notes:

  • there is no man bash in OmniOS (at least not using MANPATH=/opt/omni/share/man:/opt/mysql55/man:/opt/gcc-4.4.4/man:/usr/gnu/share/man:/usr/local/man:/usr/local/share/man:/usr/man:/usr/share/man)
  • /etc/bashrc and /etc/bash.bashrc never get sourced (which is expected as this is apparently a distribution-specific convention, but Ubuntu does appear to be loading these without reference from .bashrc)
share|improve this question

2 Answers 2

up vote 3 down vote accepted

The su command does not change the HOME environment variable under Solaris. That's just how it works. Under Linux and *BSD, su does reset HOME, I think it's a BSD/SysV difference. Bash is behaving perfectly normally: it tries to load ~/.bashrc, and since HOME is still /root, that's /root/.bashrc.

The idea is that when you su to root, the shell you start and other programs will still look for your configuration files in your home directory. If you wanted the environment of the target user, you'd run su -.

If you want to set HOME but otherwise leave the environment unchanged, set it explicitly.

HOME=~myuser su myuser

Whether bash loads a system-wide file is a compile-time option. That option is enabled on Ubuntu but disabled on OmniOS.

share|improve this answer

Is your application able to utilize SMF? If so, it might be easier to set up a service for the application.

I've seen a Python script that will make it very easy to generate an XML for SMF to utilize:
Manifold

Hope this helps.

share|improve this answer
2  
I'm afraid you've misunderstood the question. In any case, please don't just post links to external resources, instead, explain how this script would help the OP and how they could use it. –  terdon Mar 15 at 2:15

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.