Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Which profile, .bashrc or .bash_profile, is the appropriate spot for ssh-agent? I'm looking for an answer that explains the different between an interactive shell and a login shell.

share|improve this question
up vote 6 down vote accepted

It depends somewhat on how you personally use shells.

An interactive shell is anything that has a terminal connected to its input and output. Login shells are spawned by /bin/login. Login shells source your .bash_profile. Most terminal emulators such as xterm start an interactive shell that is not a login shell. Interactive, non-login shells source your .bashrc.

What I typically do is have my .bash_profile source my .bashrc (after checking if it has already been sourced), and then I put my ssh-agent setup in my .bashrc.

share|improve this answer
What's the check in .bash_profile to see if .bashrc has been sourced already? – Noah Campbell Sep 1 '09 at 21:35
Nothing special. I generally just check to see if a variable I set in .bashrc is set. – meastham Sep 1 '09 at 22:20

ssh-agent is a wrapper program.
You would typically want to do a "exec ssh-agent bash" at the start.

share|improve this answer

You should use .bash_profile because .bashrc is sourced for every interactive shell and you only need one agent per login session.

share|improve this answer

Your Answer


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.