[HOWTO] - Launch and run VNC server remotely

simon1663

Registered
Hi,
I figured out a way to launch VNC using ssh and then control it remotely. It has worked out very well for me. I thought I share this tip with others as well.

First of all, if you don’t know what VNC is, learn about it here: http://www.uk.research.att.com/vnc/

Basically, it’s a multi-platform screen control tool. It’s free and available under GPL. So, you don’t have to pay a cent to use it. Also, much simpler and better thing to use than that of Timbuktu (although not sophisticated like Timbuktu).


If you already don’t have VNC Server, download it from here: http://netmath.math.uiuc.edu/VNC-osx.htm


Install it under /Applications and then launch it. You can now test with vncthing from http://www.webthing.net/vncthing/

Note that, depending on what port you are running it on, you may have to do ip_address:<display number 1 / 2> to connect.


Anyway, we are going write a shell script now which will launch the vnc server for us from terminal.


Say you have installed OSXvnc in this directory /Applications/OSXvnc.app/

Launch terminal
Go to that directory /Applications/OSXvnc.app/ or the directory you install OSXvnc at by doing “cd /Applications/OSXvnc.app”.

Now do
cd Contents
cd macos

You will see that there are three executable files there:
“OSXvnc” , “OSXvnc-server” , “storepasswd”

storepasswd is the executable used for storing encrypted password for VNC

you can just run it to see what it has to say:
do “./storepasswd”

Say you want to store the password “mamamia” for VNC (when you connect, you will be prompted for password, and you have to type this password).

Let’s store this password by doing :
“sudo ./storepasswd mamamia ./passwdfile”
You may be asked for your password (make sure you have admin access to the computer).

Now create the file /usr/bin/launchvnc

These are the content:
vncdir=/Applications/OSXvnc.app/contents/macos
sudo -u root $vncdir/OSXvnc-server -rfbauth $vncdir/passwdfile




save and exit

Now set the permission :
“sudo chmod 755 /usr/bin/launchvnc”

Just a note that, we are doing “sudo –u root” i.e. running as the user root is because you will not get access to someone’s else’s display without being the super user. Also note that we are using the passwdfile we created earlier.


Ok, all setup done, now run a test:

Run the shell script /usr/bin/launchvnc from terminal by either doing “/usr/bin/launchvnc” or “launchvnc” if “/usr/bin” is already in your path.

You may be asked for your password.

Now try connecting with VNCThing (http://www.webthing.net/vncthing/) or any other VNC client from some other computer. Server address will be “<ip address of the machine running vnc server>:1”

Note the “:1” at the end.

Type the password you created earlier (mamamia)

And done!

Running vnc like is this is much better than just launching it startup and leaving it there. Because, then you may risk being attacked.

I use this to do system admin in my machine @ Sydney. I live 800kms down @ Melbourne.

This works with OSX 10.1 and 10.2. Should work with 10.3 when it comes out.

Also, check on versiontracker.com for more vnc stuff.

Comments, problems and suggestions at simon1663@yahoo.com
Hope it helps you.
 
There's a much easier way than that.

Download this implementation of VNC (which is the best):
http://www.redstonesoftware.com/vnc.html

Put it in your applications directory. Run it once and set your passwords and other options.

Then you can run it remotely by SSH'ing in and doing:

open /Applications/OSXvnc

Wade
 
You can even put the "open /Applications/OSXvnc" command in a shell script with a short name like "startvnc" and run it from an SSH shell.

That's what I do.
 
Does anybody else have a problem with forwarding ports through SSH under Panther, or is it just me. I set my VNC session up and I could get a connection locally, but when I forward anything to my mack as my primary user, it blows up big time. Setting up forwarding from the point localhost to my machine here at work doesn't work at all. This is most frustrating :(

The same goes for my squid forwarding. I ran ssh -v -C -L 3182:localhost:3182 to tunnel my squid connection, and not even that works. Nothing but 'connection refused'
 
OK, fixed the problem mentioned above via the following link:

SSH Problems on Panther

It boils down to this: you can no longer refer to your remote machine as 'localhost' when running ssh tunnels. Refer to them as 127.0.0.1. I knew there had to be some trick to it.
 
lowmagnet,

i am trying to setup vnc via port forwarding and one thing i found was that you are supposed to create a key. if i don't do this it lets me create the key anyway. so if it uses the key but lets anyone create one, why is it secure?
 
Is VNC better than using Apple Remote Desktop for controlling a remote computer over the internet?
 
I think Apple Remote Desktop is only Mac to Mac connection...not any computer to mac connection like VNC is
 
The advantage of VNC vs. Remote Desktop is that VNC can be used between a variety of different operating systems. For example, I can set up a VNC server on my Mac at home and connect to it with a VNC client on a Windows machine at work.

As mkwan said, Remote Desktop is strictly Mac-to-Mac.
 
lowmagnet said:
OK, fixed the problem mentioned above via the following link:

SSH Problems on Panther

It boils down to this: you can no longer refer to your remote machine as 'localhost' when running ssh tunnels. Refer to them as 127.0.0.1. I knew there had to be some trick to it.

how does one implement the ssh port forwarding? I am having a hard time connecting to the VNC server through ssh. I tried using the Panther solution and not able to connect. What am I doing wrong?
 
lowmagnet said:
Well, now the problem is that I'm getting this:



And then it crashes.

Are you by chance using "screen" to run VNC? I have this problem, too, but it seems to be the case only when I try to run from within "screen". Usually exiting screen (not detaching) and starting a new instance of screen brings it back.

I think it has something to do with process groups, and screen seems to sometimes go off in its own process group.
 
Back
Top