Mar 8, 2011

Mac OS X: Screen Sharing

How to enable a screen sharing of a remote Mac (10.6) if you forgot to enable it and your Mac is behind a firewall?

This is the question I asked myself today when I desperately was in need to use some GUI on my Mac Pro at work place, while I am on a business trip right now and have my laptop with me :(

Same as always with the Mac OS X - it appeared to be very easy to implement.

So, you have a remote Mac "A", which is behind a firewall and you want to connect to it via an open domain "B" (to where ssh is possible) from your local Mac (a laptop, for example).


Enable an SSH tunnel via an open domain to you remote Mac. On your local Mac just open a terminal and enter the following:

ssh -N -L 3000:loginnameA@hostnameA:5900 loginnameB@hostnameB

The command will create a tunnel and hang. When you are done terminate the command and the tunnel will be disabled.

Open another terminal on your local Mac and ssh to your remote Mac to enable a screen sharing:

sudo /System/Library/CoreServices/RemoteManagement/ -activate -configure -access -on -clientopts -setvnclegacy -vnclegacy yes -clientopts -setvncpw -vncpw mypasswd -restart -agent -privs -all

Start sharing the screen :)

In Safari enter the following URL: vnc://localhost:3000

Should work now :)

Disable screen sharing
SSH to your remote Mac and execute the command:

sudo /System/Library/CoreServices/RemoteManagement/ -deactivate -configure -access -off

Don't forget to terminate the SSH tunnel (Step #1).

Hope it helps some one to save time.


Sam Tseng said...

nice tips! thanks for sharing..

btw, i'm sam. the place u want to go that is mitsukoshi which is near by taipei 101. I just realized sogo is not around 101.

have a nice trip back!

Anar Manafov said...

Thanks a lot, man!
I hope to see you once again!

we keep in touch!