Step1: For those having similar issues on OS X, also make sure you have XQuartz installed,
Step2: Open terminal application from XQuartz
Step3: In the terminal, ssh -Y username@hostname
Then it should work.
Below are other options but do not work for me on MAC.
Answer: You can fix the “cannot open display” error by following the xhost procedure mentioned in this article.
Allow clients to connect from any host using xhost+
Execute the following command to disable the access control, by which you can allow clients to connect from any host.
$ xhost +
access control disabled, clients can connect from any host
Enable X11 forwarding
While doing ssh use the option -X to enable X11 forwarding.
$ ssh username@hostname -X
Enable trusted X11 forwarding, by using the -Y option,
$ ssh username@hostname -Y
Open GUI applications in that host
After opening ssh connection to the remote host as explained above, you can open any GUI application which will open it without any issue.
If you still get the “cannot open display” error, set the DISPLAY variable as shown below.
$ export DISPLAY='IP:0.0'