LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 07-01-2010, 04:43 AM   #1
stardotstar
Member
 
Registered: Nov 2002
Location: /au/qld/bne/4157
Distribution: Gentoo mactel-linux
Posts: 238

Rep: Reputation: 30
root terminal has different bash config when I ssh in vs su from another ssh account


Hi all,

Recently I created a new user on my CentOS cPanel host that could log into the system via ssh and removed the ability for root to ssh in.

Now I ssh in as the user account and then su to gain root when necessary...

Now I find that I am getting a different bash profile or environment when I su to root than when I was ssh'ing in directly...

Does that sound right?

I basically think that there must be a different bash_profile or some other relationship that is dictating a different environment when it do it each way.

Can I get some assistance on this please?

I noticed it because when I used to ssh in to the host as root I would be able to do an ifconfig for example straight from the prompt - ie the /sbin path was in the $PATH
Now I have to call the command by /sbin/ifconfig

etc.

I thought I might be getting the PATH from the original user:

Code:
root@jupiter [/home/stardotstar]# echo $PATH
/usr/local/jdk/bin:/usr/local/jdk/bin:/usr/kerberos/bin:/usr/lib/courier-imap/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin:/home/stardotstar/bin:/usr/local/bin:/usr/X11R6/bin
root@jupiter [/home/stardotstar]#
and I know this will look stupid to someone who knows how futile what I am trying to do this way is but I have tried things like:

Code:
root@jupiter [/home/stardotstar]# . /root/.bash_profile 
root@jupiter [/home/stardotstar]# ifconfig
bash: ifconfig: command not found

root@jupiter [/home/stardotstar]# . /root/.bashrc 
root@jupiter [/home/stardotstar]# ifconfig
bash: ifconfig: command not found
Can someone set me straight on this please?

TIA
\\'
 
Old 07-01-2010, 05:06 AM   #2
rsciw
Member
 
Registered: Jan 2009
Location: Essex (UK)
Distribution: Home: Debian/Ubuntu, Work: Ubuntu
Posts: 206

Rep: Reputation: 44
I assume with
. /root/.bashrc you're trying to load that one?

do

# source /root/.bashrc

in general the CentOS default setup of bash is weird imo (being used to Debian, which has a lot more set up), including the paths.

But yes, edit /root/.bashrc and run source /root/.bashrc.
This file however should be read automatically when switching to root, if bash is set for root as shell.

Which shell is set for root according to
/etc/passwd?
 
1 members found this post helpful.
Old 07-01-2010, 05:15 AM   #3
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,458
Blog Entries: 54

Rep: Reputation: 2897Reputation: 2897Reputation: 2897Reputation: 2897Reputation: 2897Reputation: 2897Reputation: 2897Reputation: 2897Reputation: 2897Reputation: 2897Reputation: 2897
When Bash is used as default shell, invoked as "/bin/bash" and starting an interactive login shell, /etc/profile is read before searching for any ~/.bash_profile, ~/.bash_login and ~/.profile in that order. See 'man bash', the "invocation" part. See the pathmunge() function in /etc/profile for path element order. Since ~/.bash_profile is read it you can also export a PATH from there. Finally note the difference between running '/bin/su -l root' and '/bin/su root'. The first invocation (with "-", "-l" or "--login" and without "-c") makes the shell an interactive login shell, the second does not. What this does for your PATH you can see by running 'echo $PATH' when trying both commands.
 
1 members found this post helpful.
Old 07-01-2010, 05:30 AM   #4
stardotstar
Member
 
Registered: Nov 2002
Location: /au/qld/bne/4157
Distribution: Gentoo mactel-linux
Posts: 238

Original Poster
Rep: Reputation: 30
WOW, awesome responses guys - thank you both.

root:x:0:0:root:/root:/bin/bash

so yes /bin/bash is the shell

and the obvious mistake I thought was using the '.' instead of 'source' but that still didn't cut it/
Code:
root@jupiter [/home/stardotstar]# source /root/.bashrc 
root@jupiter [/home/stardotstar]# ifconfig
bash: ifconfig: command not found
root@jupiter [/home/stardotstar]# source /root/.bash_profile 
root@jupiter [/home/stardotstar]# ifconfig
bash: ifconfig: command not found
I was invoking using a plain 'su'

but when I try the unSpawn approach I have these results

Code:
root@jupiter [/home/stardotstar]# exit
exit
stardotstar@jupiter [~]# su -l root
Password: 
root@jupiter [~]# echo $PATH
/usr/local/jdk/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/lib/courier-imap/sbin:/usr/lib/courier-imap/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/X11R6/bin:/root/bin
and of course all is well.
Now I just have to fully grok the goodness in that marvelous paragraph of unSpawn.

Thank you very much.
Will
 
Old 07-01-2010, 06:24 PM   #5
onebuck
Moderator
 
Registered: Jan 2005
Location: Midwest USA, Central Illinois
Distribution: SlackwareŽ
Posts: 11,281
Blog Entries: 3

Rep: Reputation: 1446Reputation: 1446Reputation: 1446Reputation: 1446Reputation: 1446Reputation: 1446Reputation: 1446Reputation: 1446Reputation: 1446Reputation: 1446
Hi,

You could setup a .bashrc & .bash_profile for your users (include root). If you source the '~/.bashrc' via the '~/.bash_profile' then no problems will occur.

My examples;

Code:
 #sample .bash_profile;
 ~$ cat .bash_profile
 # .bash_profile
 #08-30-06 12:21
 #
 # Source .bashrc
 if [ -f ~/.bashrc ]; then
         . ~/.bashrc
 fi
Code:
sample .bashrc;
 :~$ cat .bashrc
 
 #.bashrc
 #08-30-06 12:20 
 
 # Add bin to path
 
 export PATH="$PATH:/sbin:/usr/sbin:$HOME/bin"
 
 #export PATH="$PATH:$HOME/bin"
 
 # Dynamic resizing
 shopt -s checkwinsize
 
 # Custom prompt
 #PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
 
 #08-29-06 11:40
 
 if [ `id -un` = root ]; then
    PS1='\[\033[1;31m\]\h:\w\$\[\033[0m\] '
  else
    PS1='\[\033[1;32m\]\h:\w\$\[\033[0m\] '
 fi
 
 #
 # Add color
 eval `dircolors -b`
 
 # User defined aliases
 alias cls='clear'
 alias clls='clear; ls'
 alias ll='ls -l'
 alias lsa='ls -A'
 alias lsg='ls | grep'
 alias lsp='ls -1 /var/log/packages/ > package-list'
 alias na='nano'
 alias web='links -g -download-dir ~/ www.google.com'
 
 #08-29-06 11:50
 
 #To clean up and cover your tracks once you log off
 #Depending on your version of BASH, you might have to use
 # the other form of this command
    trap "rm -f ~$LOGNAME/.bash_history" 0
 
 #The older KSH-style form
 #   trap 0 rm -f ~$LOGNAME/.bash_history
The .bashrc is very useful!
 
  


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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Recover/Change UNIX root password from SSH terminal Dopamine Linux - Newbie 13 09-30-2009 06:19 PM
Get no colors on terminal using ssh to connect to apple machine(bash shell) skvikas Linux - General 4 10-24-2008 02:10 PM
Installed Freenx. Changed sshd config. Can't ssh root. CrewXp Linux - Software 1 08-13-2007 04:52 AM
Root SSH Bash Profile djhorza Linux - Software 1 12-22-2003 05:28 AM
SSH Config - non-root users toccoa Linux - Newbie 1 07-18-2003 10:07 PM


All times are GMT -5. The time now is 01:46 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration