Solved

No colors in SSH

Posted on 2008-10-04
58
1,619 Views
Last Modified: 2013-11-15
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
Comment
Question by:bswinnerton
  • 32
  • 15
  • 8
  • +1
58 Comments
 
LVL 9

Expert Comment

by:khaledf
ID: 22643297
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
 
LVL 5

Author Comment

by:bswinnerton
ID: 22643307
=/ Nothing
0
 
LVL 5

Author Comment

by:bswinnerton
ID: 22643316
Do any services need to be restarted to see a difference?
0
 
LVL 9

Expert Comment

by:khaledf
ID: 22643343
log out and log in again
0
 
LVL 5

Author Comment

by:bswinnerton
ID: 22643349
Yeah, I tried that with no luck =/
0
 
LVL 9

Expert Comment

by:khaledf
ID: 22643379
what do you get with this command

echo $PS1
0
 
LVL 5

Author Comment

by:bswinnerton
ID: 22643401
Here it is with the current .bashrc (The one I posted above)

${debian_chroot:+($debian_chroot)}\u@\h:\w\$
0
 
LVL 5

Author Comment

by:bswinnerton
ID: 22643407
And here it is with the commented and uncommented section:

(The same I believe)

${debian_chroot:+($debian_chroot)}\u@\h:\w\$
0
 
LVL 9

Expert Comment

by:khaledf
ID: 22643429
when you login as root do you get the color?
0
 
LVL 5

Author Comment

by:bswinnerton
ID: 22643438
Yes
0
 
LVL 9

Expert Comment

by:khaledf
ID: 22643448
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
 
LVL 5

Author Comment

by:bswinnerton
ID: 22643454
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
 
LVL 9

Expert Comment

by:khaledf
ID: 22643469
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
 
LVL 5

Author Comment

by:bswinnerton
ID: 22643483
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
 
LVL 48

Expert Comment

by:Tintin
ID: 22643498
Please post the output of

echo $TERM

on the server where the colour works and the server where the colour doesn't work.
0
 
LVL 5

Author Comment

by:bswinnerton
ID: 22643507
On the problematic one:

xterm-color


On the working one:

linux
0
 
LVL 5

Author Comment

by:bswinnerton
ID: 22643516
Wait a minute, hold that thought let me retest that.
0
 
LVL 5

Author Comment

by:bswinnerton
ID: 22643518
Sorry, ignore that.  They're both displaying:

xterm-color
0
 
LVL 5

Author Comment

by:bswinnerton
ID: 22655261
Anyone have any ideas?
0
 
LVL 9

Expert Comment

by:khaledf
ID: 22656486
make sure your SSH client is not overwriting system colors.
what SSH client are you using?
0
 
LVL 5

Author Comment

by:bswinnerton
ID: 22660838
Mac OSX Terminal
0
 
LVL 9

Expert Comment

by:khaledf
ID: 22661460
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
 
LVL 5

Author Comment

by:bswinnerton
ID: 22662633
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
 
LVL 51

Expert Comment

by:ahoffmann
ID: 22676662
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
 
LVL 5

Author Comment

by:bswinnerton
ID: 22679810
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
 
LVL 5

Author Comment

by:bswinnerton
ID: 22679869
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
 
LVL 5

Author Comment

by:bswinnerton
ID: 22679913
Okay found .bash* stuff as well, renaming as we speak
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 22684816
> 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
 
LVL 51

Expert Comment

by:ahoffmann
ID: 22684823
... ~ is not $HOME ..
well, in your case it seems to be the same, but i.g. they can be different
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 48

Expert Comment

by:Tintin
ID: 22684975
~ is not $HOME?

ahoffmann, in what setup is this the case?
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 22684994
> 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
 
LVL 48

Expert Comment

by:Tintin
ID: 22685391
That's a highly improbable scenario.

0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 22685449

> 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
 
LVL 5

Author Comment

by:bswinnerton
ID: 22686684
Alright, I tried
echo 'HOME=/tmp;export HOME;' >> ~/.profile

And still no colors.
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 22687297
> 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
 
LVL 5

Author Comment

by:bswinnerton
ID: 22704326
I cannot rename them, as they were never recreated from the last time that I deleted them.
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 22706236
> .. 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
 
LVL 5

Author Comment

by:bswinnerton
ID: 22706620
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
 
LVL 51

Expert Comment

by:ahoffmann
ID: 22706937
/etc/profile*
/etc/login*
/etc/bash*
0
 
LVL 5

Author Comment

by:bswinnerton
ID: 22707494
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
 
LVL 5

Author Comment

by:bswinnerton
ID: 22708669
I also noticed, that since I've done that I no longer get colors when i log in as root.
0
 
LVL 5

Author Comment

by:bswinnerton
ID: 22708676
Wait, nevermind.  I cannot login as root anymore now.
0
 
LVL 5

Author Comment

by:bswinnerton
ID: 22718219
Am I supposed to restart any services after doing this?  Nothing seems to be working =/
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 22718397
> 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
 
LVL 5

Author Comment

by:bswinnerton
ID: 22722774
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
 
LVL 5

Author Comment

by:bswinnerton
ID: 22723201
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
 
LVL 5

Author Comment

by:bswinnerton
ID: 22723225
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
 
LVL 51

Expert Comment

by:ahoffmann
ID: 22726112
> 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
 
LVL 5

Author Comment

by:bswinnerton
ID: 22728108
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
 
LVL 51

Expert Comment

by:ahoffmann
ID: 22729736
> 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
 
LVL 5

Author Comment

by:bswinnerton
ID: 22732589
-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
 
LVL 51

Accepted Solution

by:
ahoffmann earned 500 total points
ID: 22738109
perfect, that looks like a clean environment
What happens if you now set:

PS1='\033[01;32m\]\u@\h\ $\[\033[00m\] '
0
 
LVL 5

Author Comment

by:bswinnerton
ID: 22742424
Where would I set that? In .bashrc?  I don't have a .bashrc file.
0
 
LVL 5

Author Comment

by:bswinnerton
ID: 22742513
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
 
LVL 51

Expert Comment

by:ahoffmann
ID: 22744678
> Where would I set that?
on the command line, just copy&paste ..
0
 
LVL 5

Author Comment

by:bswinnerton
ID: 22747187
Yes, that gives it much more color =) However it does not stay after logging in again.
0
 
LVL 51

Assisted Solution

by:ahoffmann
ahoffmann earned 500 total points
ID: 22749774
> .. 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
 
LVL 51

Expert Comment

by:ahoffmann
ID: 22752857
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Hello to you all, I hear of many people congratulate AWS (Amazon Web Services) on how easy it is to spin up and create new EC2 (Elastic Compute Cloud) instances, but then fail and struggle to connect to them using simple tools such as SSH (Secure…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now