الثلاثاء، ٣٠ يونيو ٢٠٠٩

SSH and X11 forwarding problem in mac os

I was trying to run an application on my macBook Leopard 10.5.7 that opens some X windows from a remote server but the X forwarding did not work. I spent few hours trying to fix the problem and searched the internet with no luck.
Finally I figured that the whole problem was caused by my SSH configuration.
The machine was not excepting remote ssh access eventhough the remote login was enabled from the sharing menue.
The error that I got when I tried to run the sshd server manually was:
Could not load host key: /etc/ssh_host_rsa_key
Could not load host key: /etc/ssh_host_dsa_key

To fix the ssh I created the missing keys using the following commands which fixed the ssh but not the X forwarding:
sudo ssh-keygen -t dsa -f /etc/ssh_host_dsa_key -N ''
sudo ssh-keygen -t rsa1 -f /etc/ssh_host_rsa_key -N ''

To make the X forwarding work one more step is needed. In /etc/sshd_config change the following lines:
sudo vi /etc/sshd_config
#AllowTcpForwarding yes
#GatewayPorts no
X11Forwarding yes
X11DisplayOffset 10
#X11UseLocalhost yes

Then go to your application directory > Utilities > X11
in the preferences go to security tab and check allow connections from network clients.

Now you need to log out then log in to restart the X server
Finally run
xhost +
to disable access control form remote hosts.

Then restart the sshd or reboot.