In my SSH config file, X forwarding is enabled, and I run ssh with the -X parameter. It gives me first error below but connects in the end.

Failed to add the host to the list of known hosts (/home/myUserName/.ssh/known_hosts)

The problem starts here. When I open an X program such as ff, it opens on the remote machine, not through forwarding to my computer. Am I mixing something? How can I forward X output to my local machine?

Both machines have a Linux operating system with X.org installed with perfectly working desktop environments.

echo $DISPLAY outputs :0
  • 1
    After logging in to the remote system, could you run "echo $DISPLAY" and edit your question to include the result? Are there any lines in your .profile, .bashrc, or similar files, that set the DISPLAY environment variable?
    – Kenster
    Sep 11, 2015 at 17:17
  • @Kenster added the output outputs :0
    – nikoss
    Sep 12, 2015 at 13:38
  • You should look at @gilles' answer. If ssh forwards X correctly, it'll set DISPLAY to something like "localhost:10". If DISPLAY is set to something else, it suggests that something in your .profile, .bashrc, or similar file is overriding DISPLAY and setting it to something incorrect. That is what you need to fix.
    – Kenster
    Sep 12, 2015 at 15:33

1 Answer 1


If you connect with SSH and you run an X11 application, and that X11 application displays on the remote machine instead of through the SSH connection, there are three possible reasons.

  • The application is one of the few applications that only ever start a single instance for a given user on a given machine, and it's already launched on a different display.
  • You're attaching an existing Screen or Tmux session which was started from a local GUI session. A program knows where it should open its window from the value of the DISPLAY environment variable. Inside that Screen/Tmux, the DISPLAY environment variable remains what was initially set. You need to change it when you reconnect to an existing session: run echo $DISPLAY before attaching to the terminal multiplexer, and set the variable inside the multiplexer.
  • You did something naughty in one of your configuration files (.profile, .bashrc, etc.): you changed the DISPLAY environment variable. Apart from the case of attaching to a screen multiplexer that was started from another display, you should never set DISPLAY manually. If you SSH into somewhere and DISPLAY isn't set, that means that the SSH connection isn't forwarding an X11 connection, and setting the environment variable manually cannot help.

So in all likelihood what you need to do is to go through your configuration files and remove the line that corrupts the DISPLAY environment variable.

  • I'll check as soon as possible the application was not launched on the machine its for sure I'll try about display variable thank you
    – nikoss
    Sep 12, 2015 at 4:41
  • io added display output to the question
    – nikoss
    Sep 12, 2015 at 13:38
  • @nikoss :0 designates the local display. SSH uses numbers starting at 10. You need to find the configuration file where you wrote something like export DISPLAY=:0 and remove it. Sep 12, 2015 at 13:45
  • i removed .bashrc but will it make problem next time when computer attepts to startx automatically
    – nikoss
    Sep 12, 2015 at 17:14
  • @nikoss startx doesn't belong in .bashrc. In .profile, maybe, but conditionally, only if you run it on the console. Sep 12, 2015 at 18:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .