2

Every time i ssh into my raspberry pi, i get message:

Cannot open display "default display"

I've tried going into raspi-config and installing all the locales. Doesn't change anything. I've then tried googling it and nothing seems to work.

What do I do to make it go away?

10
  • Are you logging in using a console and trying to run GUI apps? Commented Jan 5, 2020 at 20:43
  • im logging in via terminal. no im not trying to run gui apps, not even -x with the ssh.
    – john-jones
    Commented Jan 5, 2020 at 21:01
  • What app are you using to make the SSH connection? Commented Jan 5, 2020 at 21:03
  • no app. just terminal.
    – john-jones
    Commented Jan 5, 2020 at 21:06
  • 1
    you're right. in the bashrc file i was sourcing multiple other files. and it turned out to be an xkeymap call that caused the message. Turns out the x in xkeymap is for... -x. I was so thinking this was some locale problem configurable in the raspi-config for raspbian has this locale setting problem i was always dealing with that caused errors akin to this one, so i was on the wrong track. Can just post an answer and i'll accept it.
    – john-jones
    Commented Jan 5, 2020 at 22:43

2 Answers 2

4

This is a very common sign that there is something in the remote user's .bashrc file that tries to start something that wants to use the X display. That is what the message usually means.

A lazy way around this is to edit the logged in user's .bashrc and make the last line to be the clear command.
Advantage: hides the problem.
Disadvantage: you'll never know what is causing it.

Best practice is to go through the .bashrc file and find if anything is being run that needs a running Xserver. Also maybe try looking in /var/log/syslog for clues.

1
  • 1
    Love the 'clear' solution. Problem still exists but you don't see it.
    – gnuchu
    Commented Mar 1, 2021 at 13:18
4

in the bashrc file i was sourcing multiple other files. and it turned out to be an xkeymap call that caused the message. Turns out the x in xkeymap is for... -x

You can test whether a console login is via SSH or not like this

if [[ $(who -m) =~ \([-a-zA-Z0-9\.]+\)$ ]] ; then
echo "SSH session"
else
echo "not SSH session"
fi

who -m produces hostname and user associated with stdin, and in an SSH shell there is output, and none in a GUI terminal, which we can test for. who plus two dummy arguments will produce the same effect, e.g. who am i (very popular), who mom likes or who a b etc.

The top grab is my Rpi4 GUI, the bottom is an SSH login from my Windows PC using wsltty.

enter image description here

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.