• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1672
  • Last Modified:

No colors in SSH

Hi there everyone,

I don't know what i've done, but for some reason when I SSH into my server, i don't see the green text in user@domain.com.

However I can login to a different server and get it, and I can also su on the problematic server and i get color.

From what i've heard, it has something to do with my .bashrc, but I'm not sure what it's supposed to look like. Here is my current one in the directory of the user i'm logging in as.


# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
 
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
 
# don't put duplicate lines in the history. See bash(1) for more options
#export HISTCONTROL=ignoredups
 
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize
 
# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(lesspipe)"
 
# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "$debian_chroot" -a -r /etc/debian_chroot ]; then
    debian_chroot=$(cat /etc/debian_chroot)
fi
 
# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
xterm-color)
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
    ;;
*)
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
    ;;
esac
 
# Comment in the above and uncomment this below for a color prompt
#PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
 
# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
    PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD/$HOME/~}\007"'
    ;;
*)
    ;;
esac
 
# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.
 
#if [ -f ~/.bash_aliases ]; then
#    . ~/.bash_aliases
#fi
 
# enable color support of ls and also add handy aliases
if [ "$TERM" != "dumb" ]; then
    eval "`dircolors -b`"
    alias ls='ls --color=auto'
    #alias dir='ls --color=auto --format=vertical'
    #alias vdir='ls --color=auto --format=long'
fi
 
# some more ls aliases
#alias ll='ls -l'
#alias la='ls -A'
#alias l='ls -CF'
 
# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
#if [ -f /etc/bash_completion ]; then
#    . /etc/bash_completion
#fi

Open in new window

0
bswinnerton
Asked:
bswinnerton
  • 32
  • 15
  • 8
  • +1
2 Solutions
 
khaledfCommented:
the attached file says
# Comment in the above and uncomment this below for a color prompt
#PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
try it and and see if it fixes the issue
0
 
bswinnertonAuthor Commented:
=/ Nothing
0
 
bswinnertonAuthor Commented:
Do any services need to be restarted to see a difference?
0
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
khaledfCommented:
log out and log in again
0
 
bswinnertonAuthor Commented:
Yeah, I tried that with no luck =/
0
 
khaledfCommented:
what do you get with this command

echo $PS1
0
 
bswinnertonAuthor Commented:
Here it is with the current .bashrc (The one I posted above)

${debian_chroot:+($debian_chroot)}\u@\h:\w\$
0
 
bswinnertonAuthor Commented:
And here it is with the commented and uncommented section:

(The same I believe)

${debian_chroot:+($debian_chroot)}\u@\h:\w\$
0
 
khaledfCommented:
when you login as root do you get the color?
0
 
bswinnertonAuthor Commented:
Yes
0
 
khaledfCommented:
replace this
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '

with

PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
0
 
bswinnertonAuthor Commented:
Where do I replace it?  In the .bashrc I have:

# Comment in the above and uncomment this below for a color prompt
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ 'PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ 'PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '

Would i just take it all out and put :

# Comment in the above and uncomment this below for a color prompt
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
0
 
khaledfCommented:
it should be like

# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
 
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
 
# don't put duplicate lines in the history. See bash(1) for more options
#export HISTCONTROL=ignoredups
 
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize
 
# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(lesspipe)"
 
# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "$debian_chroot" -a -r /etc/debian_chroot ]; then
    debian_chroot=$(cat /etc/debian_chroot)
fi
 
# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
xterm-color)
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
    ;;
*)
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
    ;;
esac
 
# Comment in the above and uncomment this below for a color prompt
#PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
 
# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
    PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD/$HOME/~}\007"'
    ;;
*)
    ;;
esac
 
# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.
 
#if [ -f ~/.bash_aliases ]; then
#    . ~/.bash_aliases
#fi
 
# enable color support of ls and also add handy aliases
if [ "$TERM" != "dumb" ]; then
    eval "`dircolors -b`"
    alias ls='ls --color=auto'
    #alias dir='ls --color=auto --format=vertical'
    #alias vdir='ls --color=auto --format=long'
fi
 
# some more ls aliases
#alias ll='ls -l'
#alias la='ls -A'
#alias l='ls -CF'
 
# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
#if [ -f /etc/bash_completion ]; then
#    . /etc/bash_completion
#fi

Open in new window

0
 
bswinnertonAuthor Commented:
Sorry to be such a pain, but still no luck. I am editing /home/administrator/.bashrc, and yes I'm logging in as administrator.  Should I be editing the /root/.bashrc file?

I'm really confused as to why this isn't working anymore.
0
 
TintinCommented:
Please post the output of

echo $TERM

on the server where the colour works and the server where the colour doesn't work.
0
 
bswinnertonAuthor Commented:
On the problematic one:

xterm-color


On the working one:

linux
0
 
bswinnertonAuthor Commented:
Wait a minute, hold that thought let me retest that.
0
 
bswinnertonAuthor Commented:
Sorry, ignore that.  They're both displaying:

xterm-color
0
 
bswinnertonAuthor Commented:
Anyone have any ideas?
0
 
khaledfCommented:
make sure your SSH client is not overwriting system colors.
what SSH client are you using?
0
 
bswinnertonAuthor Commented:
Mac OSX Terminal
0
 
khaledfCommented:
it seems you have color preferences set for that connection unintentionally .try to remove color preferences and see. I don't know how to do it, maybe someone could help here.
0
 
bswinnertonAuthor Commented:
Well it must be a server side issue, because i can log on as a different user on the mac and still have no colors.  Does anyone have any idea how to fix this?
0
 
ahoffmannCommented:
please remove/rename all your ~/.bash* and ~/.profile and ~/.log* files for the problematc user
then login and issue a set and printenv command, please post following variables (case sensitive!):

HOME
SHELL
TERM
COLORTERM
SSH*

(where SSH* means all variables which start with SSH)

also print result of following command:

echo ~
0
 
bswinnertonAuthor Commented:
I couldn't seem to find .bash, .profile or .log  (This is a ubuntu server with no GUI).
Here is the printout of printenv with the variables you requested:

HOME --> /
SHELL --> /bin/bash
TERM --> xterm
COLORTERM --> (Nothing came up here)
SSH_CLIENT=10.0.0.17 1130 22
SSH_TTY=/dev/pts/0
 
echo ~ --> /
0
 
bswinnertonAuthor Commented:
I'm sorry, i was using the wrong command for search.  I have renamed .profile to .profile_old (The only one that I could find in /home/administrator)
0
 
bswinnertonAuthor Commented:
Okay found .bash* stuff as well, renaming as we speak
0
 
ahoffmannCommented:
> The only one that I could find in /home/administrator)
no, no,
I said you need to do that in ~
~ is not $HOME and is not /home/administrator
0
 
ahoffmannCommented:
... ~ is not $HOME ..
well, in your case it seems to be the same, but i.g. they can be different
0
 
TintinCommented:
~ is not $HOME?

ahoffmann, in what setup is this the case?
0
 
ahoffmannCommented:
> ahoffmann, in what setup is this the case?
echo 'HOME=/tmp;export HOME;' >> ~/.profile

then login again (assuming that you use sh or friends and not csh as login shell)
0
 
TintinCommented:
That's a highly improbable scenario.

0
 
ahoffmannCommented:

> improbable
have seen infinite .profile, even /etc/profile and other shell rc-files where smart admins tried to change HOME (also USER and SHELL) and then wonder why a couple of software won't run anymore or as expected.
I've learned the lession (to deal with stupid admins:)  and always use ~
KISS - keep  it simple stupid
0
 
bswinnertonAuthor Commented:
Alright, I tried
echo 'HOME=/tmp;export HOME;' >> ~/.profile

And still no colors.
0
 
ahoffmannCommented:
> echo 'HOME=/tmp;export HOME;' >> ~/.profile
bswinnerton, this was not intended for you to execute, but for Tintin to test.
Please remove the line
   HOME=/tmp
in your ~/.profile as it may crash your login.

Then please follow http:#22676662 in your ~ (home) directory of the user having these problems.
Ensure that you have removed HOME=/tmp in profile before logging in again.
0
 
bswinnertonAuthor Commented:
I cannot rename them, as they were never recreated from the last time that I deleted them.
0
 
ahoffmannCommented:
> .. that I deleted them.
perfect:)
So you don't have any of
  ~/.profile
  ~/.bash*
  ~/.login

If so, and you still get no colours, then please disable corresponding files in /etc (I'd rename, not delete), and log in again.
0
 
bswinnertonAuthor Commented:
Well I did rename them, I just wanted you to be sure that they were gone =)

And as for the corresponding files in /etc ... Which ones do you mean?
0
 
ahoffmannCommented:
/etc/profile*
/etc/login*
/etc/bash*
0
 
bswinnertonAuthor Commented:
Alright, I renamed the following:

/etc/bash.bashrc
/etc/bash_completion
/etc/login.defs
/etc/profile

And now when I login, i get:

-bash-3.2$

As opposed to:

username@mydomain.com

But still no color.
0
 
bswinnertonAuthor Commented:
I also noticed, that since I've done that I no longer get colors when i log in as root.
0
 
bswinnertonAuthor Commented:
Wait, nevermind.  I cannot login as root anymore now.
0
 
bswinnertonAuthor Commented:
Am I supposed to restart any services after doing this?  Nothing seems to be working =/
0
 
ahoffmannCommented:
> I cannot login as root anymore now.
please restore /etc/login.defs

then login and post following information:


  printenv|egrep '(HOME|SHELL|TERM|SSH|BASH|COLO)'
  echo ~
  ls -la ~/.{profile,bashrc,bash_profile,bash_login,login}
0
 
bswinnertonAuthor Commented:
Alright, Here is what I got (The ip addresses and ports are removed for privacy):

-bash-3.2$ printenv|egrep '(HOME|SHELL|TERM|SSH|BASH|COLO)'
TERM=xterm-color
SHELL=/bin/bash
SSH_CLIENT=sourceip port 22
SSH_TTY=/dev/pts/0
HOME=/
SSH_CONNECTION=sourceip port destinationip 22

-bash-3.2$ echo ~
/

ls -la ~/.{profile,bashrc,bash_profile,bash_login,login}
ls: cannot access /root/.bash_profile: No such file or directory
ls: cannot access /root/.bash_login: No such file or directory
ls: cannot access /root/.login: No such file or directory
-rw-r--r-- 1 root root 2227 2007-05-15 12:07 /root/.bashrc
-rw-r--r-- 1 root root  164 2008-10-10 09:33 /root/.profile



0
 
bswinnertonAuthor Commented:
As you can see I had to login as root to get the last command to work. Here is what I get if i am not logged in as root:

ls: cannot access //.profile: No such file or directory
ls: cannot access //.bashrc: No such file or directory
ls: cannot access //.bash_profile: No such file or directory
ls: cannot access //.bash_login: No such file or directory
ls: cannot access //.login: No such file or directory
0
 
bswinnertonAuthor Commented:
Here are the contents of /home/administrator incase they help at all:

-bash-3.2$ ls -s -h -a /home/administrator
total 162M
4.0K .
4.0K ..
4.0K ._example_config.xml
4.0K ._example_urllist.txt
4.0K .bash_history_old
4.0K .bash_logout_old
4.0K .bashrc_old
4.0K .profile_old
4.0K .ssh
   0 .sudo_as_admin_successful
0
 
ahoffmannCommented:
> HOME=/
> ls -la ~/.{profile,bashrc,bash_profile,bash_login,login}
> ls: cannot access /root/.bash_profile: No such file or directory

so we see what I tried to explain you multiple times:
  $HOME is different to the home directory specified in /etc/passwd

we also see:
> -rw-r--r-- 1 root root 2227 2007-05-15 12:07 /root/.bashrc
> -rw-r--r-- 1 root root  164 2008-10-10 09:33 /root/.profile
that you did not follow my suggestion: please rename these files and login again

> Here are the contents of /home/administrator
and again: what is that directory for (I already asked that!

bswinnerton, I know it may be hard, but please follow the suggestion *exactly*, don't do anything else, don't do additional things without knowing 101% what's the result, and post all exactly what you do and what you get (copy&paste verbatim please).

@Tintin,
you see that it is once more *not improbable*, we have to beat and teach stupid admins settings again ;-)
0
 
bswinnertonAuthor Commented:
ahoffmann,

As posted above here is what you told me to do:

>please remove/rename all your ~/.bash* and ~/.profile and ~/.log* files for the problematc user
>then login and issue a set and printenv command, please post following variables (case sensitive!):

>HOME
>SHELL
>TERM
>COLORTERM
>SSH*

I removed all of those from the user ADMINISTRATOR!!!! not root.  Root is working fine.

As you obviously missed from above I posted that I logged in to root the first time and then showed you what the output of just administrator was:

>As you can see I had to login as root to get the last command to work. Here is what I get if i am not >logged in as root:

>ls: cannot access //.profile: No such file or directory
>ls: cannot access //.bashrc: No such file or directory
>ls: cannot access //.bash_profile: No such file or directory
>ls: cannot access //.bash_login: No such file or directory
>ls: cannot access //.login: No such file or directory
0
 
ahoffmannCommented:
> I removed all of those from  ..
no you did not, or how comes following (your post):
   ls -la ~/.{profile,bashrc,bash_profile,bash_login,login}
  -rw-r--r-- 1 root root 2227 2007-05-15 12:07 /root/.bashrc
  -rw-r--r-- 1 root root  164 2008-10-10 09:33 /root/.profile

> .. and then showed you what the output of just administrator was:
may be this was confusing (me), hence I ask again for:

  id
  printenv|egrep '(HOME|SHELL|TERM|SSH|BASH|COLO|USER)'
  echo ~
  ls -la ~/.{profile,bashrc,bash_profile,bash_login,login}

** plaese do this when logged in as that user which you encounter your problems,
** don't log in using su, login from a console or use ssh
0
 
bswinnertonAuthor Commented:
-bash-3.2$ id
uid=1000(administrator) gid=1000(administrator) groups=0(root),4(adm),20(dialout),24(cdrom),25(floppy),29(audio),30(dip),40(src),44(video),46(plugdev),104(scanner),109(lpadmin),110(admin),1000(administrator)

-bash-3.2$ printenv|egrep '(HOME|SHELL|TERM|SSH|BASH|COLO|USER)'
TERM=xterm-color
SHELL=/bin/bash
SSH_CLIENT=sourceip port 22
SSH_TTY=/dev/pts/0
USER=administrator
HOME=/
SSH_CONNECTION=sourceip port destinationip 22

-bash-3.2$ echo ~
/

-bash-3.2$ ls -la ~/.{profile,bashrc,bash_profile,bash_login,login}
ls: cannot access //.profile: No such file or directory
ls: cannot access //.bashrc: No such file or directory
ls: cannot access //.bash_profile: No such file or directory
ls: cannot access //.bash_login: No such file or directory
ls: cannot access //.login: No such file or directory



0
 
ahoffmannCommented:
perfect, that looks like a clean environment
What happens if you now set:

PS1='\033[01;32m\]\u@\h\ $\[\033[00m\] '
0
 
bswinnertonAuthor Commented:
Where would I set that? In .bashrc?  I don't have a .bashrc file.
0
 
bswinnertonAuthor Commented:
Incase you forgot..
-bash-3.2$ ls -la ~/.{profile,bashrc,bash_profile,bash_login,login}
ls: cannot access //.profile: No such file or directory
ls: cannot access //.bashrc: No such file or directory
ls: cannot access //.bash_profile: No such file or directory
ls: cannot access //.bash_login: No such file or directory
ls: cannot access //.login: No such file or directory

0
 
ahoffmannCommented:
> Where would I set that?
on the command line, just copy&paste ..
0
 
bswinnertonAuthor Commented:
Yes, that gives it much more color =) However it does not stay after logging in again.
0
 
ahoffmannCommented:
> .. that gives it much more color =)
ha, we got it.
one of your rc-files (one of those being renamed or deleted:) destroys the proper settings for your colour.
Either find out which one it is, or write your own ones.

If you encounter this bahviour (no colours) for all users, then the culprit is most likely to be found in /etc, otherwise in the user's home directory (which is ~)

I guess it's time to punish your admin, too ;-)
0
 
ahoffmannCommented:
Glad to have solved this problem.

This thread is a good example how some admins misconfigure a system (shell) in diligence but ignorance, just because the are too lazy to read simple man-pages carefully.
As I already said: I've seen countless such rc-files which make a system run into various errors. And IIRC most of these example I found in files named .bash*. It's time to give up my amazement about the name of this shell: bash, which must be from the verb not the noun.
:() { :; };:

No offence meant to people listening or writing comments here;-)
*SCNR*
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 32
  • 15
  • 8
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now