 |
 |
problem with bash_profile and bashrc
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Nov 2004
Status:
Offline
|
|
Hey,
I installed fileutils using apt-get and changed my .bash_profile and .bashrc accordingly. However, when I try to ssh in my root account(yes, I know I shouldn't do that normally), I still don't get to use the "ls" command from fileutils. I tried
Code:
sh .bash_profile
sh .bashrc
but nothing happened. However if I do a
everything seems fine, meaning I get to use all the commands in /sw folder. Below is my .bash_profile and .bashrc
Code:
# .bash_profile
. /sw/bin/init.sh
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH
unset USERNAME
# .bashrc
# User specific aliases and functions
PS1="\u@\h \w>\$ "
eval `dircolors /etc/DIR_COLORS`
alias ls='ls --color=auto'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias vi='vim'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-ti
lde'
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
Does anyone know why sshd doesn't execute .bash_profile and .bashrc? (I tried with 777 permission but no luck.)
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Oct 1999
Location: :ИOITAↃO⅃
Status:
Offline
|
|
Just to be clear, you installed these in root's home folder, your own, or both?
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Jan 2001
Location: Mahwah, NJ USA
Status:
Offline
|
|
Originally posted by scabbage:
Hey,
I installed fileutils using apt-get and changed my .bash_profile and .bashrc accordingly. However, when I try to ssh in my root account(yes, I know I shouldn't do that normally), I still don't get to use the "ls" command from fileutils.
Whoa there! ... (in response to the "Hey")
First, you shouldn't even have the root account enabled, let alone ssh in as the root user. Please disable it immediately. Since you enabled it you already know how to disable it. The "approved" alternatives are to log in as a regular user and either:
sudo somecommand
or
sudo -s
Ctrl-d to exit
or
sudo su -
Ctrl-d to exit
You will find that the above alternatives will give you all the rootlike utility that you need and minimize the chances of you shooting yourself in the foot. I am not talking down to you... that is how professional sysadmins with decades of experience use the root account... the reason they do it is so they can minimize the chances of shooting themselves in the foot.
Next, there is no particular reason I know of to install "fileutils" via "apt-get" in Mac OS X. Mac OS X already has a working "ls" command in the BSD subsystem. I suspect that you are using Fink, yes?
I tried
Code:
sh .bash_profile
sh .bashrc
but nothing happened.
Yes you can do that but .bash_profile and .bashrc are not really shell scripts, they are configuration files. The correct syntax is:
Code:
source .bash_profile
source .bashrc
If bash is the default shell for the user you log in as then you shouldn't need to do any of that. You can check this by just typing the command 'echo $SHELL' at the prompt. If you want to see how everything in your shell environment is set just type 'set'. You might want to pipe it through 'less' though.... like this, 'set | less'.
However if I do a
everything seems fine, meaning I get to use all the commands in /sw folder. Below is my .bash_profile and .bashrc
Code:
# .bash_profile
. /sw/bin/init.sh
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH
unset USERNAME
# .bashrc
# User specific aliases and functions
PS1="\u@\h \w>\$ "
eval `dircolors /etc/DIR_COLORS`
alias ls='ls --color=auto'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias vi='vim'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-ti
lde'
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
OK it is not at all clear where you got this .bash_profile and .bashrc from. I will assume that they are located in the root users home folder.
To fix this you need to do several things:
1. As before, disable the root user account.
2. ssh to your system as a a regular user. I am assuming that your regular user account is also an admin account, yes? You can check this in System Preferences --> Accounts --> Security the 'Allow user to administer this computer' should be checked.
3. While logged in as the admin user (NOT as root) check which is your default shell and path.
echo $SHELL
You should see '/bin/bash' If not, what do you see?
echo $PATH
You should see something like
'/sw/bin:/sw/sbin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin'
If not, what do you see?
4. If you see your $PATH as above everything should be fine... just to check do.
which ls
You should see '/sw/bin/ls' If not, what do you see?
Get back to us with the information above and we can then straighten this little mess out.
Does anyone know why sshd doesn't execute .bash_profile and .bashrc? (I tried with 777 permission but no luck.)
sshd works just fine. It may be that you are unaware of how you really have things set up. We will help you find out and straighten it out.
(I say "we" because this is a public forum and anyone can jump in. I do not mean it as the royal "we".  )
|
|
-DU-...etc...
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Nov 2004
Status:
Offline
|
|
To fix this you need to do several things:
1. As before, disable the root user account.
2. ssh to your system as a a regular user. I am assuming that your regular user account is also an admin account, yes? You can check this in System Preferences --> Accounts --> Security the 'Allow user to administer this computer' should be checked.
3. While logged in as the admin user (NOT as root) check which is your default shell and path.
echo $SHELL
You should see '/bin/bash' If not, what do you see?
echo $PATH
You should see something like
'/sw/bin:/sw/sbin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin'
If not, what do you see?
4. If you see your $PATH as above everything should be fine... just to check do.
which ls
You should see '/sw/bin/ls' If not, what do you see?
Get back to us with the information above and we can then straighten this little mess out.
Now I'm stuck at step 1. I remember I enabled root account by doing
The problem is I'm not sitting in front of the Mac. (If I do, I know I can disable root account by going to preference > accounts, right?) I can only access the machine using ssh. Mind shed some light on that?
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Jan 2001
Location: Mahwah, NJ USA
Status:
Offline
|
|
Originally posted by scabbage:
Now I'm stuck at step 1. I remember I enabled root account by doing
The problem is I'm not sitting in front of the Mac. (If I do, I know I can disable root account by going to preference > accounts, right?) I can only access the machine using ssh. Mind shed some light on that?
Interesting. I am not sure how to do it via commandline in Mac OS X, it is possible though. Usually one opens Netinfo Manager in Macintosh HD --> Applications --> Utilities then from the Security menu in the menubar select 'Disable root user'. It may be greyed out and you will have to Authenticate first (also in that menu).
OK did some digging and a recent article on Apples forums with the exact same question came up, see: http://discussions.info.apple.com/we...cb736.68a1126f
for the procedure.
I have never seen the root account show up in System Preferences --> Accounts activated or not.
|
|
-DU-...etc...
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Nov 2004
Status:
Offline
|
|
Now the problem is fixed. Thanks for the post on "How to deactivate root", utidjian. I haven't tried it though. I realized that when fink (yes, i use fink, not apt-get) was installed (on command line), it doesn't change the /etc/bashrc and /etc/profile file. So that's why I don't have /sw/bin in my $PATH. So I copied the /etc/profile from another machine into this one, which is shown here:
Code:
# System-wide .profile for sh(1)
PS1='\u \w>\$ '
PATH="/opt/coreutils-5.0/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin"
export PATH PS1
eval `dircolors /etc/DIR_COLORS`;
[ -r /etc/bashrc ] && source /etc/bashrc
#env initializtion for fink
. /sw/bin/init.sh
## setloginpath added /usr/local/bin start at Fri Oct 29 01:41:19 CDT 2004
## Do not remove the previous line
if [ `whoami` != "root" ]
then
PATH="$PATH:/usr/local/bin"
export PATH
fi
## Do not remove the next line
## setloginpath added /usr/local/bin end at Fri Oct 29 01:41:19 CDT 2004
## TeX modifications start at Fri Oct 29 02:01:02 CDT 2004
## Do not remove the previous line
if [ `whoami` != "root" ]
then
PATH="$PATH:/usr/local/teTeX/bin/powerpc-apple-darwin-current"
export PATH
fi
## Do not remove the next line
## TeX modifications end at Fri Oct 29 02:01:02 CDT 2004
One thing I'm still confused is the fact that my .bashrc file didn't get executed before I changed the /etc/profile file. Anyways, thanks for the help.
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Jan 2001
Location: Mahwah, NJ USA
Status:
Offline
|
|
Originally posted by scabbage:
Now the problem is fixed. Thanks for the post on "How to deactivate root", utidjian. I haven't tried it though. I realized that when fink (yes, i use fink, not apt-get) was installed (on command line), it doesn't change the /etc/bashrc and /etc/profile file.
And nor should it! The "prefered" way of using fink is to NOT have it touch ANY of the main Apple installed side of the system but for each user that wants to use fink to be able to add the '. /sw/bin/init.sh' directive to their respective ~/.bash_profile as they see fit. Now it may be that the system you are using has been upgraded from 10.2 (or earlier) and was not a "clean" 10.3 install. This might explain why the ~/.bashrc and ~/.bash_profile files were never read. (That is why I asked you to run those other commands in previous posts).
I hope you have since disabled the root account.
So that's why I don't have /sw/bin in my $PATH. So I copied the /etc/profile from another machine into this one, which is shown here:
No, that is incorrect... but for the right reason.
Code:
# System-wide .profile for sh(1)
PS1='\u \w>\$ '
PATH="/opt/coreutils-5.0/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin"
export PATH PS1
eval `dircolors /etc/DIR_COLORS`;
[ -r /etc/bashrc ] && source /etc/bashrc
#env initializtion for fink
. /sw/bin/init.sh
## setloginpath added /usr/local/bin start at Fri Oct 29 01:41:19 CDT 2004
## Do not remove the previous line
if [ `whoami` != "root" ]
then
PATH="$PATH:/usr/local/bin"
export PATH
fi
## Do not remove the next line
## setloginpath added /usr/local/bin end at Fri Oct 29 01:41:19 CDT 2004
## TeX modifications start at Fri Oct 29 02:01:02 CDT 2004
## Do not remove the previous line
if [ `whoami` != "root" ]
then
PATH="$PATH:/usr/local/teTeX/bin/powerpc-apple-darwin-current"
export PATH
fi
## Do not remove the next line
## TeX modifications end at Fri Oct 29 02:01:02 CDT 2004
That is quite a bit different than the "standard" /etc/profile. There is nothing wrong with having it that way if you are the only user of the system. However if it is a multi-user system now ALL users have their $PATHs modified by /etc/profile. That may not be what you or they want.
One thing I'm still confused is the fact that my .bashrc file didn't get executed before I changed the /etc/profile file. Anyways, thanks for the help.
It is most likely because your default shell was not actually bash but tcsh (or something else). If it was tcsh then .bashrc and .bash_profile would never be sourced on login. Again, that is why I asked you to run those other commands. If you do:
sudo nidump passwd . | grep youruserid
You should get something like:
youruserid:********:502:502::0:0:youruserid:/Users/youruserid:/bin/bash
Note the last thing on the end of that line. If it doesn't say /bin/bash then ~/.bashrc and/or ~/.bash_profile will never be sourced unless after you log in you then type 'bash' at the command prompt. For more information on this see 'man bash' and look under the section called 'INVOCATION'.
I hope that is clear enough for you. If not let me know.
|
|
-DU-...etc...
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Nov 2004
Status:
Offline
|
|
I hope you have since disabled the root account.
Yes, I did.
Now I guess I understand what the problem was. These are my bash config files:
Code:
#/etc/profile
# System-wide .profile for sh(1)
PATH="/bin:/sbin:/usr/bin:/usr/sbin"
export PATH
[ -r /etc/bashrc ] && source /etc/bashrc
Code:
#/etc/bashrc
# System-wide .bashrc file for interactive bash(1) shells.
PS1='\h:\w \u\$ '
# Make bash check it's window size after a process completes
shopt -s checkwinsize
if [ -f ~/.bashrc ];
then
. ~/.bashrc
fi
Code:
# .bashrc
# User specific aliases and functions
alias ls='ls --color'
alias l.='ls -d .* --color=tty'
alias ll='ls -l --color=tty'
alias ls='ls --color=tty'
alias vi='vim'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
alias gettorrent='/Users/instructor/Documents/tmp/BitTorrent-3.4.2/btdownloadcurses.py --display_interval 5'
Code:
# .profile
test -r /sw/bin/init.sh && . /sw/bin/init.sh
eval `dircolors /etc/DIR_COLORS`;
I remember I installed fink using command line. One thing about doing that is I have to manually run /sw/bin/pathsetup.sh and what it does is adding
Code:
test -r /sw/bin/init.sh && . /sw/bin/init.sh
to my .profile. Because I didn't do that, my $PATH wasn't setup correctlly. Plus, my .bashrc didn't get executed because I didn't include
Code:
if [ -f ~/.bashrc ];
then
. ~/.bashrc
fi
in the /etc/bashrc file. Thanks for all the help.
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|