Ask Ubuntu is a question and answer site for Ubuntu users and developers. 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

When I connect over ssh to remote hosts everything is just a single font/color. I would like to have colours like I do locally e.g. green for executable and blue for symlinks etc. And such that when I run $ git diff on the ssh host it shows me diff with colours =)

share|improve this question
    
Is that an Ubuntu server you're connecting to? – Stefano Palazzo Dec 5 '10 at 20:42
    
@stefano-palazzo: to Debian. – Dima Dec 6 '10 at 0:46
up vote 17 down vote accepted

Hm. since it was xterm on the server, I figured something was wrong with .bashrc

And indeed! --color=auto works only when you are connected to TTY. Changing everything to simply --color in .bashrc and everything is in pretty colours now.

share|improve this answer
    
You should mark this as the answer :) – djeikyb Feb 23 '11 at 2:44
15  
It would help this answer a lot if you said where you put --color=auto. .bashrc on the server? What commands? – rfay Aug 24 '13 at 19:37
1  
Since this is an old question which is still relevant, I just wanted to add that on Ubuntu systems, the default .bashrc has a case statement which defines which terms are allowed color. If you find the "case "$TERM$" in" line in your .bashrc, adding "xterm) color_prompt=yes;;" will also enable color. Also you can uncomment the "force_color_prompt=yes" line to globally enable it always. – Mike E Jul 6 '15 at 17:58

What's the content of your XTERM env variable on the server when you connect to it?

~ > export | grep -i term
TERM=xterm
share|improve this answer
    
$ export | grep -i term declare -x TERM="xterm" – Dima Dec 6 '10 at 0:36

Seems like colors were already set in ~/.bashrc for me and the issue is that ssh does not use the bashrc file. You can use bashrc in your ssh session by adding the following to ~/.bash_profile:

if [ -f ~/.bashrc ]; then
      . ~/.bashrc
fi
share|improve this answer

I tried changing ~./bashrc settings (both on local and remote server), but it did not seem to work.

Then I noticed that ~/.bashrc of remote server does not even get executed if I connect to it over ssh. So I made ~/.bashrc of remote server to execute by puttinng if [ -f ~/.bashrc ]; then . ~/.bashrc fi in remote server's ~/.bash_profile. (based on http://stackoverflow.com/questions/820517/bashrc-at-ssh-login).

So this solution did not require changing any ~/bashrc files directly but it did require changing ~/bash_profile file of remote server so that ~/bashrc file of remote server got executed.

share|improve this answer
    
Ubuntu uses .profile and not .bash_profile by default, and the default .profile does source .bashrc. – muru Mar 7 at 22:18
    
That is correct. But does .profile get executed by default when logging in through ssh? – chris544 Mar 7 at 22:43
    
Yes. Provided you didn't override it using .bash_profile, bash runs .profile when started as a login shell. And SSH starts bash as a login shell. – muru Mar 7 at 22:44
    
It is correct that ~/.profile is not read if ~/.bash_profile exists. But doesn't ~/.bash_profile exist on Ubuntu by default? – chris544 Mar 7 at 22:51
    
See my first comment again. No, it doesn't. Ubuntu uses .profile. – muru Mar 7 at 22:52

Your Answer

 
discard

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.