Start a remote access server from the shell

Dec 06, '01 05:16:35PM

Contributed by: sharumpe

If you're like me, you use VNC for remote GUI access, but don't want to keep the server running when you aren't using it due to security concerns. Here's how you can start a VNC server on demand via ssh.

First, create a script called /pathto/yourscripts/startvncserver as follows:

#!/bin/tcsh
cp /pathto/yourscripts/.osxvnc-passwd /tmp/osxvnc-passwd
/Applications/OSXvnc.app/Contents/MacOS/OSXvnc-server -rfbport 5901
-desktop "OSX VNC 1" -rfbauth /tmp/osxvnc-passwd &
[This is a three line script; remove the line break after the "5901" when entering it.]

Save it wherever you save your own scripts, and make it executable (i.e. chmod 755 startvncserver).

The next step is to make the osxvnc-passwd file. All you need to do is start a VNC server via the GUI (with a password), and copy /tmp/osxvnc-passwd to /pathto/yourscripts/.osxvnc-passwd

All set! Now you can SSH to your machine, start VNC with your new script, and then connect via the GUI.

Note: A user must be logged into the console at the remote machine, or I don't think this will work. I'm going to test it without being logged in and I'll post a comment with the results.

Comments (11)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20011206171635606