Link to home
Start Free TrialLog in
Avatar of bswinnerton
bswinnertonFlag for United States of America

asked on

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

Avatar of khaledf
khaledf

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
Avatar of bswinnerton

ASKER

=/ Nothing
Do any services need to be restarted to see a difference?
log out and log in again
Yeah, I tried that with no luck =/
what do you get with this command

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

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

(The same I believe)

${debian_chroot:+($debian_chroot)}\u@\h:\w\$
when you login as root do you get the color?
Yes
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\]\$ '
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\]\$ '
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

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.
Avatar of Tintin
Please post the output of

echo $TERM

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

xterm-color


On the working one:

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

xterm-color
Anyone have any ideas?
make sure your SSH client is not overwriting system colors.
what SSH client are you using?
Mac OSX Terminal
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.
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?
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 ~
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 ~ --> /
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)
Okay found .bash* stuff as well, renaming as we speak
> 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
... ~ is not $HOME ..
well, in your case it seems to be the same, but i.g. they can be different
~ is not $HOME?

ahoffmann, in what setup is this the case?
> 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)
That's a highly improbable scenario.


> 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
Alright, I tried
echo 'HOME=/tmp;export HOME;' >> ~/.profile

And still no colors.
> 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.
I cannot rename them, as they were never recreated from the last time that I deleted them.
> .. 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.
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?
/etc/profile*
/etc/login*
/etc/bash*
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.
I also noticed, that since I've done that I no longer get colors when i log in as root.
Wait, nevermind.  I cannot login as root anymore now.
Am I supposed to restart any services after doing this?  Nothing seems to be working =/
> 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}
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



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
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
> 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 ;-)
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
> 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
-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



ASKER CERTIFIED SOLUTION
Avatar of ahoffmann
ahoffmann
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Where would I set that? In .bashrc?  I don't have a .bashrc file.
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

> Where would I set that?
on the command line, just copy&paste ..
Yes, that gives it much more color =) However it does not stay after logging in again.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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*