LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 05-15-2014, 08:49 AM   #1
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194
should ~/.bashrc run in an ssh session?


I thought my ~/.bashrc script should be executed when I ssh to a shared Centos system.

I tested and determined that it is not.

Is something configured wrong in that Centos system, that I should ask our IT person to correct? Or is it normal for ssh to start a bash session without using ~/.bashrc?

If it is normal for ~/.bashrc to not be executed, is there a better place I should put the commands that I want executed each time I log in via ssh?
 
Old 05-15-2014, 09:14 AM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668
~/.bash_profile gets executed and it usually contains the setup to source ~/.bashrc if it exists. Something like:

Code:
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi
 
1 members found this post helpful.
Old 05-15-2014, 09:17 AM   #3
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,185

Rep: Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377
Quote:
Originally Posted by johnsfine View Post
I thought my ~/.bashrc script should be executed when I ssh to a shared Centos system.

I tested and determined that it is not.
I assume you've checked that your actual login shell is set to bash?
 
Old 05-15-2014, 09:47 AM   #4
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Original Poster
Rep: Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194
Solved: I had not understood the relationship between .bashrc and .bash_profile and I did not have a .bash_profile file.

Once I knew (from MensaWater's post) what to google search for, it was easy to find the relationship between the two and decide that for simple situations, like I have, my .bash_profile file should exist and should source .bashrc

Now it all works.
 
Old 05-15-2014, 10:11 AM   #5
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2138Reputation: 2138Reputation: 2138Reputation: 2138Reputation: 2138Reputation: 2138Reputation: 2138Reputation: 2138Reputation: 2138Reputation: 2138Reputation: 2138
Quote:
Originally Posted by johnsfine View Post
Solved: I had not understood the relationship between .bashrc and .bash_profile and I did not have a .bash_profile file.

Once I knew (from MensaWater's post) what to google search for, it was easy to find the relationship between the two and decide that for simple situations, like I have, my .bash_profile file should exist and should source .bashrc

Now it all works.
Keep in mind that not all distros work that way. OpenSUSE, for example, does not have a .bash_profile file but it does have a functioning .bashrc. It depends on how /etc/profile is configured on each particular distro.
 
1 members found this post helpful.
  


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
make commands keep running after leaving a terminal session or ssh session Danny3031 Programming 18 01-30-2012 11:29 AM
How to edit .bashrc such that I don't need to export on every new session? golmschenk Linux - Newbie 3 03-07-2011 09:20 PM
Run intractive ssh session in a bash script MasterC Programming 2 10-15-2007 05:08 PM
How to run a program in an ssh session that will run after you close out the session? dr_zayus69 Linux - Networking 5 03-05-2006 07:15 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 10:44 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration