Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Using VNC from the Terminal UNIX
OSX has a nifty program called Screen Sharing. It lets you remotely access other computers, whether they be UNIX, Mac, Linux, Windows, or any other type of box. All the other box needs is a VNC server, which Macs have built in since 10.4.

However, using this app directly is often a pain. You have to open it up, create a new session, type in the URL/IP, and then possibly authenticate. If you, like me, are accustomed to using Terminal for most of your tasks, there is an easier and quicker way: use the "open" command, which is built in to OSX.

From a standard shell, run open as in one of these examples:

open vnc://www.example.com
open vnc://111.111.111.111
open vnc://mylocalserver.local

If you often VNC into the same computer, you can create an alias in your shell's profile so you don't have to type the command every time. Combine this with QuickSilver, and you can open a VNC connection to the server of your choice in as little as 5 key-strokes!

[crarko adds: I tested this, and it works as described. This is an elaboration of an earlier hint.]
    •    
  • Currently 4.00 / 5
  You rated: 3 / 5 (5 votes cast)
 
[33,578 views]  

Using VNC from the Terminal | 25 comments | Create New Account
Click here to return to the 'Using VNC from the Terminal' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
VNC from Terminal on OSX
Authored by: kyngchaos on Sep 28, '10 08:11:53AM

You can do the same from the Finder:

Go->Connect to Server. Or Command-k.

Type in the same "vnc://..." as above (without the "open" part). You can save connection shortcuts here also.



[ Reply to This | # ]
VNC from Terminal on OSX
Authored by: diamondsw on Sep 28, '10 08:26:13AM

And of course, the "open" command can be used to open anything that LaunchServices can - files, applications, URL's, and optionally specify the app to open them with. Very powerful command - even if this is a bit of an odd use for it.

You can do all you describe, or just go to the Finder (Command-Tab: 2), Connect to Server (Command-K: 4), navigate to your favorite server, and connect (Enter: 5). There - 5 keystrokes from Terminal to connecting, and no aliases or shell machinations, and it works from any app - since you're command-tabbing to the Finder first. It would be much nicer if Screen Sharing.app would bring up your favorite VNC locations when launched from the Dock, but sadly a trip to the Finder is necessary. You could always put those favorites on the Dock as well, but then you'd lose out on keyboard access.



[ Reply to This | # ]
Not on nonstandard ports
Authored by: theosib on Sep 28, '10 08:52:24AM

This doesn't work if your VNC server is on a nonstandard port. I serve multiple VMs from one server, so I have to put each on a different port, and I can't access them this way.

I tried "open vnc://192.168.1.30:9001" to no avail.



[ Reply to This | # ]
Not on nonstandard ports
Authored by: ekc on Sep 28, '10 10:24:49AM

Strange. I use a non-standard port when I'm running vnc over an ssh tunnel and that syntax has always worked fine for me.



[ Reply to This | # ]
VNC from Terminal on OSX
Authored by: peterholdn on Sep 28, '10 12:08:33PM

I know this won't work in all cases, but for the other computers on my home network, there's the even easier built-in way of doing this.

In the finder, in the sidebar, other computers on the network show up under "Shared", and it's only two clicks to open a screen sharing session. One on the computer in the sidebar, one on the "share screen" button that subsequently shows up.

I believe that there was some initial setup for this, but now it's just a matter of a couple clicks.

---
Relax, it's only ones and zeroes.



[ Reply to This | # ]
I use Safari
Authored by: kiltbear on Sep 28, '10 12:23:30PM

I just type vnc://blah.tld.com into the safari location bar and it launches screen sharing.



[ Reply to This | # ]
I use Safari
Authored by: chris_on_hints on Sep 28, '10 12:55:18PM

...me too. Even better, you can drag the location from the safari location bar and drop it on your desktop to create a convenient shortcut!



[ Reply to This | # ]
I use Safari
Authored by: gidds on Sep 28, '10 02:47:26PM

Excellent! TVM for the hint. (Just got a Mac Mini, so was looking for a quicker way to launch VNC/Screen Sharing.)

---
Andy/



[ Reply to This | # ]
I use Safari
Authored by: blackketter on Sep 28, '10 02:59:04PM

Yep, and you can save them as bookmarks in Safari. I've done that, then use LaunchBar to open them quickly.



[ Reply to This | # ]
VNC from Terminal on OSX
Authored by: petergort on Sep 28, '10 03:18:13PM

don't forget that you can embed the authentication like this
vnc://username:password@ipaddressordomain
if it's a mac that you are remoting into. Setting them up as a shell alias is one way to do it. Storing them in Safari's bookmarks and the authentication in your keychain is another. Since I mostly work graphically and seldom in terminal, I put all my remote control links in a folder in my bookmarks bar. This has the side effect of also making them available on my iPad, and since I have iTeleport on my iPad the links work from there too.



[ Reply to This | # ]
VNC Shortcut with Hidden Credentials
Authored by: RichB on Sep 28, '10 11:27:19PM
There is also the built-in Finder capability to create a "VNC Internet Location" file with an extension of ".vncloc" similar to a "Web Location" file storing afp, smb or http credentials in a ".webloc" file. This is cool. I just learned it is possible the same way an afp or smb shortcut can be made with credentials embedded:
  • Create the desired connection text in Text Edit or wherever, for example, "vnc://username:password@ipaddressordomain".
  • Select the entire text (without quotes) "vnc://username:password@ipaddressordomain". This is similar to what I've done for years with afp server connections like this: "afp://username:password@ipaddressordomain".
  • Click and drag the text selection
  • Drag it to the desktop or any Finder window and a new file is created
  • The name of the file created will be the same as the selected text followed by the extension, for example, "vnc://username:password@ipaddressordomain.vncloc" (the extension is normally hidden)
  • Change the file name to whatever is desired, for example, "Mac Mini Screen Sharing.vncloc" (don't change the extension if visible)
  • The contents of the small file are not easily accessible so could be safely copied to other computers or sent as an email attachment to other Mac users, for example a spouse, as an easy shortcut to just double-click to start the screen sharing.


  • [ Reply to This | # ]
    VNC from Terminal on OSX
    Authored by: asmeurer on Sep 29, '10 08:33:20AM
    Really, don't put the password in the link. You realize that this will allow anyone with internet access to remotely access the machine in question, if they have it. Doesn't the Screen Sharing application have keychain support? If so, I would recommend using that instead.

    And to the other poster, it is extremely easy to view the contents of the file. Just type cat file in the terminal. Actually, there's really no need to examine the file anyway, since it has the password in there, anyone who wants to use it just needs to open it (if they are on a Mac).

    [ Reply to This | # ]
    VNC from Terminal on OSX
    Authored by: ozcaveboy on Sep 28, '10 04:15:44PM

    For the more GUI-inclined, try a free utility called Screen Sharing Menulet

    http://www.klieme.com/ScreenSharingMenulet.html

    It sits in the menu bar and automatically shows any Macs on the local subnet with screen sharing enabled. You can also add other computers by IP address. As a Mac administrator, I find it invaluable for quick remote access for troubleshooting.



    [ Reply to This | # ]
    VNC from Terminal on OSX
    Authored by: lsequeir on Sep 29, '10 05:38:27AM

    I don't remember where I got it from (maybe here on macosxhints?), but here is my favorite solution: just drag the folder ~/Library/Application Support/Screen Sharing to the dock.

    (This folder contains a file with extension .vncloc for each machine that you have accessed for screen sharing)

    Click once to show the machines you've used Screen Sharing with; click a second time to select the one you want and there you go.

    ---
    Luís



    [ Reply to This | # ]
    VNC from Terminal on OSX
    Authored by: taxi on Sep 29, '10 06:24:12AM
    If you want to connect to a machine via an IPv6 address, then you can use:
        vnc://[abcd:0123:ffff:ffff::4567]
    
    using the IPv6 address, obviously.

    [ Reply to This | # ]
    VNC from Terminal on OSX
    Authored by: asmeurer on Sep 29, '10 08:40:15AM

    Seriously? "on OSX"? For one thing, it's "OS X," and for another, this is Mac OS X hints, which should imply that anyway.



    [ Reply to This | # ]
    Quicksilver is dead
    Authored by: capacity on Sep 30, '10 10:32:41AM
    This doesn't pertain to the main topic of this hint, but since you mentioned Quicksilver I felt the need to say:
    Quicksilver is dead, long live Quick Search Box: http://code.google.com/p/qsb-mac/

    [ Reply to This | # ]
    Quicksilver is dead
    Authored by: philostein on Sep 30, '10 11:45:52AM

    Really? What am I using then?



    [ Reply to This | # ]
    Quicksilver is dead
    Authored by: capacity on Oct 05, '10 08:31:30AM

    No need to be a jerk.

    As far as I knew, QSB was the successor to QS. Thanks to your snide comment and some searching around on my part, I now know that QS has moved from its long-hosted blacktree location <http://www.blacktree.com/projects/quicksilver.html> and now exists as github project <http://github.com/tiennou/blacktree-alchemy>.



    [ Reply to This | # ]
    Quicksilver is dead
    Authored by: philostein on Oct 05, '10 04:20:35PM

    A bugbear of mine about this site is the use of absolute statements based on personal experience or personal preference. I'm sorry, I thought your comment was based on the latter.



    [ Reply to This | # ]
    VNC from Terminal on OSX
    Authored by: PlanBForOoo on Oct 01, '10 06:19:37AM

    <blockquote>just drag the folder ~/Library/Application Support/Screen Sharing to the dock.</blockquote>

    Except ~/Library/Application Support/Screen Sharing does not exist on my Mac OS X 10.5.8. Any idea why?



    [ Reply to This | # ]
    VNC from Terminal
    Authored by: RichB on Oct 02, '10 02:09:11PM

    Have you used Screen Sharing to connect to another Mac? The folder is created the first time used.

    Edited on Oct 02, '10 02:20:25PM by RichB



    [ Reply to This | # ]
    VNC from Terminal
    Authored by: PlanBForOoo on Oct 08, '10 10:18:26AM

    Thanks Rich,
    sure I use it on a daily basis (hence my desire to improve the abysmal poor user interface).

    I run on 10.5.8 and the application has not created such a folder. The screen sharing app used to remeber a list of visited serves, but at some point (with some action or update) this disappeared. All I have now is Apple+N to start a small dialog for the server I want to connect to.

    I did create such a folder myself and added *.vncloc files with the vnc:// URl in ot but that does not work either.



    [ Reply to This | # ]
    VNC from Terminal
    Authored by: PlanBForOoo on Oct 14, '10 06:32:29AM

    I'm on 10.5.8 and this does not work.

    What works is type vnc://mypc.example.com/ into safari and drag the little icon into a folder in finder. This creates a file named vnc--mypc.example.com.inetloc with some binary content.

    If you like you can drag the folder with such *.inetloc shortcuts to the dock in order to show as a fan or grid.



    [ Reply to This | # ]
    Using VNC from the Terminal
    Authored by: jcypher on May 01, '11 03:30:44PM

    Safari can directly handle vnc:// URIs. Also, you can directly use the Finder (under Go > Connect to server...) to save your vnc:// URIs, where you can optionally store credentials to those vnc servers in your keychain.



    [ Reply to This | # ]