Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

I have a colorful bash terminal (e.g. ls and vim show colors when configured to do so).

How can I have these colors when connecting to a remote server via ssh?

share|improve this question
up vote 2 down vote accepted

Read the subsection from "Beyond Linux From Scratch" book:

This script uses the ~/.dircolors and /etc/dircolors files to control the colors of file names in a directory listing. They control colorized output of things like ls --color. The explanation of how to initialize these files is at the end of this section.

cat > /etc/profile.d/ << "EOF"
# Setup for /bin/ls and /bin/grep to support color, the alias is in /etc/bashrc.
if [ -f "/etc/dircolors" ] ; then
        eval $(dircolors -b /etc/dircolors)

        if [ -f "$HOME/.dircolors" ] ; then
                eval $(dircolors -b $HOME/.dircolors)
alias ls='ls --color=auto'
alias grep='grep --color=auto'
share|improve this answer
Can you expand your answer a little? The question has 2,800 views — would be great to add a little more context. – slhck Jun 25 '12 at 20:18
Fedora 20 also comes with a script. – Cristian Ciupitu May 30 '14 at 2:32

Using a combination of and nik's answer you can do:

ssh -t '. /etc/profile; . ~/.profile; /bin/bash'

This will execute your profile scripts on login, then open a bash shell. Your profile scripts are where the colors are defined.

Or, for maximum convenience, add the following to your ~/.ssh/config file:

Host *
  LocalCommand . /etc/profile; . ~/.profile; /bin/bash
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.