I have a PHP program and in order to run a batch file, I have typed:

$> xhost +
$> ssh username@hostname -X
$> ssh username@hostname -Y

And, it works fine. But, my problem is that when I restart my computer or download something, I have to do this all over again.

Is there a way to enable X11 forwarding permanently on a pc? I have to mention that X11 forwarding is yes in configuration file, but I have to type the mentioned commands for my GUI to work.

2 Answers 2


You don't need (and don't want) xhost +.

Just update (or create) your .ssh/config file with the following for the equivalent of -X:

Host *
ForwardX11 yes

Or for the equivalent of -Y:

Host *
ForwardX11Trusted yes

This will affect your connections to all hosts. You can of course use something other than * to limit these configurations changes to particular hosts/domains/etc.

  • OK Thank you, I am going to update the .ssh/config file, but why "You don't need (and don't want) xhost +." ?
    – Jack
    Aug 24, 2015 at 16:59
  • You don't want it because that permits anyone, on any host anywhere, to access your X display (where "access" means "able to grab anything on your screen, your keystrokes, etc). It's not necessary because ssh manages X display authentication for you, using MIT-MAGIC-COOKIE authentication.
    – larsks
    Aug 24, 2015 at 17:32

In ~/.ssh/config have something like this:

Host server1
   HostName server1
   ForwardX11 yes
   User username

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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