Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Is there any way to change it from the default 5900 to some other port?

share|improve this question
    
At least disable connections from everything except localhost to 5900; Securing OS X with ipfw - CS Labs Wiki –  user104072 Nov 4 '11 at 1:25
add comment

3 Answers 3

up vote 11 down vote accepted

You actually can switch the default port for Apple's VNC server on Mac OS 10.7 Lion and 10.8 Mountain Lion. To change the port, you need to edit the server's plist file /System/Library/LaunchDaemons/com.apple.screensharing.plist (this file doesn't exist in systems prior to 10.7 Lion).

Editing the file requires root (sudo) privileges. In the terminal, if you are familiar with vi or vim, you can type:

sudo vim /System/Library/LaunchDaemons/com.apple.screensharing.plist

or if you're not, you'd better use nano:

sudo nano /System/Library/LaunchDaemons/com.apple.screensharing.plist

Now, all you have to do is change line 34 (the one that reads <string>vnc-server</string>) to <string>nnnn</string> where nnnn is the port number you wish to use. I know it seems weird changing a name like "vnc-server" to a number, but that's the way you have to do it. I've included an example below in case anything's not clear.

To change the default port to 54321, you would edit the plist file to look like this:

...
<key>Sockets</key>
  <dict>
      <key>Listener</key>
      <dict>
          <key>Bonjour</key>
          <string>rfb</string>
          <key>SockServiceName</key>
          <string>54321</string>            <!-- Change this line! -->
      </dict>
  </dict>
  <key>UserName</key>
  <string>root</string>
  <key>SHAuthorizationRight</key>
  <string>system.preferences</string>
</dict>
</plist>

After saving the file, to make the change take effect, turn Screen Sharing off and then on again in the Sharing preference pane, or alternatively unload and re-load the service using these commands:

sudo launchctl unload /System/Library/LaunchDaemons/com.apple.screensharing.plist
sudo launchctl load /System/Library/LaunchDaemons/com.apple.screensharing.plist
share|improve this answer
    
If you're still around -- once you've done this, is there a comparable way to get the built-in Mac screensharing app to connect to that port, or are you stuck using third-party vnc apps that let you specify the port? –  Jim Miller Sep 19 '13 at 14:11
1  
Answer to above: In "Connect to server...", specify vnc://yourserver.com:54321 (following the earlier example re port number) –  Jim Miller Sep 19 '13 at 14:36
    
If this works (I can't check until tonight) you deserve a whole lot more upvotes. –  PaulSkinner Oct 11 '13 at 10:14
1  
To confirm, yes you would need to do this after each OS update (including incremental updates). –  PaulSkinner Oct 24 '13 at 6:54
1  
Also you can set ADDITIONAL port for Screen Sharing to listen, so you will have two or more ports available for this. Just add one more <key>SockServiceName</key><string>NNNN</string> –  khrf May 8 at 14:45
show 1 more comment

This has been discussed on various forums at apple.com and on macosxhints.com. The short answer is "you can't change it".

The longer answers suggest ways around it -- three possibilities:

  • Use alternate VNC server software
  • Use an ssh tunnel to redirect traffic from your custom port to 5900
  • Configure port mapping in your router to take incoming traffic on a different port to go to port 5900 on your mac.
share|improve this answer
    
Just for the sake of completeness: some suggest that changing the ports in /etc/Services might do the trick. I tried that (I even rebooted my Mac after changing it) to no avail. And giving it some more thought, it might even be a bad idea to mess with that file, as other applications might also use it to get the well-known port number if they want to connect to some third-party using a specific protocol. (Like: changing the SSH port in that file might seem to work but is a bad idea.) –  Arjan Dec 1 '10 at 11:07
1  
Note the answer by Greg Canty -- it can be changed on OS X releases after Snow Leopard. This answer was originally written before OS X Lion was released. –  Doug Harris Nov 21 '13 at 18:36
add comment

I can confirm after finding this thread via Google that editing /ect/services for the "rfb" ports will redirect the included VNC server's listening ports.

I edited the file and rebooted (usually I'd try restarting services or unloading the launchdeamon but I was having some other issues as well and didn't bother). iTeleport on my iPad then failed to connect on 5900 and succeeded on the high unprivileged port I chose.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.