On a dedicated server we use the shell is setup differently between accounts, which is quite irritating. When I ssh into most users I get:

[user@machine some_dir]$

However, with some accounts I get:


I keep a lot of shells open to various machines, and there are a lot of different accounts. I have the ability to either make everyone have the same ~/.bashrc, but I also believe there is a global config somewhere in /etc

What's the fastest way to make sure I get the same shell whenever I ssh?


Your best bet is a mix of the two approaches. Bash will always load ~/.bashrc. You should place a standard file in /etc/skel/.bashrc and ~/.bashrc that in turn sources something like /etc/bash.bashrc. (The version in skel will get used for new user accounts.) Put your defaults in the latter file.

Example user .bashrc:

# this line activates the system-wide default settings
. /etc/bash.bashrc

# users can add any custom .bashrc settings here

Example /etc/bash.bashrc based on my prompt:

PS1='\A \['$G'\]\u@\h \['$Y'\]\w\['$N'\] \$ '

With this setup, you can later change the system-wide prompt and add other settings without having to edit everybody's .bashrc file. Hope that helps.

  • This would be horrible to maintain. If you wanted to change system-wide performance later, you would have to modify each individual .bashrc in the user's home directory. You're also recreating existing native performance. Finally, .bashrc is for non-login shells. .bash_profile is for login shells. See INVOCATION in the manpage. – Warner Jul 6 '10 at 21:05
  • Where can I find the settings that are being used for other accounts? – Kristopher Ives Jul 6 '10 at 21:14
  • Warner: No, it wouldn't be a problem to maintain. I specifically set it up so that you can just edit /etc/bash.bashrc after you are done to change system-wide behavior. Also, I know about the login vs. non-login issue and chose bashrc specifically; if you set the prompt in .bash_profile, it will not apply to non-login xterms, because they don't have any login shell in the parent processes. Ideally, .bash_profile or /etc/profile should source ~/.bashrc so that the prompt settings apply to all interactive shells. – Walter Mundt Jul 6 '10 at 23:48
  • @Krisropher: I don't understand your question. Every account works the same: Non-login interactive shells (xterms, shells in GNU screen, etc.) read ~/.bashrc. Login shells (SSH or terminal logins) will instead read /etc/profile and then the first of ~/.bash_profile, ~/.bash_login or ~/.profile that exists; oftentimes one of those will source the user's ~/.bashrc so that settings in .bashrc apply to all interactive shells as I mention in my previous comment. – Walter Mundt Jul 6 '10 at 23:58
  • @Warner: One more point, in reply to your statement that I am recreating existing native functions. AFAIK, there is no system-wide file that all interactive shells read on startup. Login shells read /etc/profile but non-login interactive shells only read ~/.bashrc, so everything important has to go in the latter in my experience, or that file has to include something system-wide. – Walter Mundt Jul 7 '10 at 0:08

/etc/profile is the standard location for the system-wide bash configuration on most systems.

From the bash manpage:

       When executing interactively, bash displays the primary prompt PS1 when
       it  is  ready  to  read a command, and the secondary prompt PS2 when it
       needs more input to complete  a  command. 
  • /etc/profile is the best place to put this for login shells, use /etc/bash.bashrc as well for nonlogin shells. – theotherreceive Jul 7 '10 at 9:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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