rcmdnk's blog

Japanese ver.: Macに外部からアクセス出来るようにする方法
Apple MacBook Pro MD101LL/A 13.3-Inch Laptop

It is useful if you have a way to access to your Mac from other machines.

Here is my summary of how to access to Mac.

Sponsored Links

SSH

In OSX, it is easy to run ssh server.

To enable ssh server, open System Preferences Sharing.

macssh

Then, enable Remote Login, that’s all.

pencil In OSX, sshd is automatically launched by launchd when ssh access is detected. You see sshd in such ps -A|grep ssh only when ssh connections to your Mac exist.

You can find the IP address (ssh <USER>@<IP address>) and host name (<ComputerName>.local) of your machine in above Sharing window.

Try

$ ssh localhost

from your Mac or try

$ ssh <USER>@<IP address>

from other machines.

Here, OSX has a special configuration file, /System/Library/LaunchDaemons/ssh.plist, in addition to /etc/sshd_config.

Although there is /etc/sshd_config, even if you change a line in the file like:

Port 23

the port for ssh is not changed.

To change the port, edit the value of key SockServiceName in /System/Library/LaunchDaemons/ssh.plist, like:

/System/Library/LaunchDaemons/ssh.plist
1
2
3
4
5
6
7
8
9
10
11
12
13
14
 <key>Sockets</key>
 <dict>
   <key>Listeners</key>
   <dict>
     <key>SockServiceName</key>
-      <string>ssh</string>
+      <string>23</string>
     <key>Bonjour</key>
     <array>
       <string>ssh</string>
       <string>sftp-ssh</string>
     </array>
   </dict>
 </dict>

With a default key value of ssh, the port is set as 22.

Although most options can be configured in /etc/sshd_config as usual, such port option is overwritten by /System/Library/LaunchDaemons/ssh.plist.

warning You must not remove <key>SockServiceName</key> value from /System/Library/LaunchDaemons/ssh.plist. It will make sshd not working even if you set a port correctly in sshd_config.


To restart sshd to reflect these changes, uncheck and check Remote Login in Sharing, or execute following commands from command line:

$ sudo launchctl unload /System/Library/LaunchDaemons/ssh.plist
$ sudo launchctl load /System/Library/LaunchDaemons/ssh.plist

Now, you should be able to:

$ ssh -p 23 localhost

VNC

It is easy to run vnc server, too.

Just check Screen Sharing in Sharing window, then vnc server will start.

VNC’s default port is 5900. To change this port, again, use a configuration file under LaunchDaemons, /System/Library/LaunchDaemons/com.apple.screensharing.plist.

/System/Library/LaunchDaemons/com.apple.screensharing.plist
1
2
3
4
5
6
7
8
9
10
11
 <key>Sockets</key>
 <dict>
   <key>Listener</key>
   <dict>
     <key>Bonjour</key>
     <string>rfb</string>
     <key>SockServiceName</key>
-    <string>vnc-server</string>
+    <string>15900</string>
   </dict>
 </dict>

The value of vnc-server of SockServiceName represents a port number 5900. You can set as you like as above.

To restart vnc server, like ssh server, uncheck and check Screen Sharing, or execute following commands from command line:

$ sudo launchctl unload /System/Library/LaunchDaemons/com.apple.screensharing.plist
$ sudo launchctl load /System/Library/LaunchDaemons/com.apple.screensharing.plist

Now you can access to your Mac by VNC, and if you have another Mac, VNC viewer is available by default.

To use vnc viewer in Mac, open finder, go to menu Go, and select Connect to Server... (or -K).

macvnc

Fill your server Mac’s IP address after vnc://, and you can open connect to your server Mac by vnc.

Dynamic DNS

To use ssh or vnc, you need to know the IP address of the server.

If you have static IP address, it is easy, but normally it needs additional cost to have such static IP address.

On the other hand, there are many free services of Dynamic DNS (DDNS).

I’m using No-IP. In the free edition, you need to confirm every 2 months (being noticed by email), and domain names are limited. But I think that is no problem for light usage.

To use DDNS in Mac, get a host name from No-IP, install Dynamic Update Client (DUC), and setup DUC with the host name you got from No-IP.

Back to My Mac

If you want to connect Mac to Mac, you can use iCloudBack to My Mac.

Enable Back to My Mac, and enable File Sharing in Sharing, then your Mac information is sent through iCloud and is given a unique number and IPv6 IP address. You can use host name like <ComputerName>.<UniqueNumber>.members.btmm.icloud.com.

You can access from another Mac with these host name or IP address.

To check your host name and IP address, run dsn-sd -E from terminal:

$ dns-sd -E
Looking for recommended registration domains:
DATE: ---Mon 19 Jan 2014---
00:00:00.000  ...STARTING...
Timestamp     Recommended Registration domain
00:00:00.001  Added                          local
00:00:00.002  Added                          icloud.com
                                             - > btmm
                                             - - > members
                                             - - - > 123456789

The last number is the given unique number. You can access this Mac from another Mac (both machines are synchronized by iCloud) by:

$ ssh <USER>@<ComputerName>.123456789.members.btmm.icloud.com`

Other Web Services

For screen sharing, you can use such TeamViewer instead of VNC.

TeamViwer doesn’t require IP address, it can connect if your Mac is connected to the internet. And you can use TreamViewer in free for personal usage.

There are server/client softwares for Windows, Mac, Linux, and for mobiles (Android, iOS, etc…).

Free TeamViewer Download for Mac

Previously, I used similar service, LogMeIn, but now a free edition of it was terminated, so that I moved to TreamViewer.

In Japanese:

Macに外部からアクセス出来るようにする方法

Sponsored Links
Sponsored Links

« Prevent to disconnect a ssh connection by 'Connection reset by peer' Notice a copy event on your blog in Google Analytics »

}