Options for file sharing via SSH in OS X
Apple's Remote Login feature in OS X can be used for securely transferring files using several protocols.
Remote access to a computer system is a convenient option to have, as it can allow you to change settings, get to your files and folders, or otherwise use the system without needing to be immediately in front of it. Being a Unix-like system, Apple has included the popular SSH remote log-in service for administering the system via the command line. However, this service can be used for more than a text-based interface to running commands, and you can use it to create secured FTP connections and similarly mount remote folders on a local system using the SSH filesystem (SSHFS) protocol.
If you are a UNIX-guru or are otherwise familiar with the BSD command line interface, then Apple's inclusion of the remote log-in service "SSH" will likely be familiar to you. Even if you are just starting out with running basic commands and scripts, the remote log-in service may be beneficial for running your tasks from remote locations.
To set up a remote log-in session, you first need to enable SSH by checking the "Remote Login" service in the Sharing system preferences. This will enable the service, but in addition you will need to specify which users may access the system via SSH. By default, all local users will have access, but you can restrict this list by specifying users. Do be careful that you do not specify a blank list of users, as this will prevent SSH connections from working properly.
Once enabled, you can log into the system using an SSH client, which in most Unix terminals will be a command similar to the following:
In most cases the host name will either be the fully qualified domain name of the server if one is assigned to it, or it can be the IP address of the server. Alternatively for OS X systems, on local networks you can also use the system's bonjour name, which can be looked up in the "Sharing" system preferences immediately below the computer name setting (it should be the computer name followed by ".local").
While SSH is a powerful option for connecting to a system, using it is similar to being directly on the system and while you can use it to manage files on the remote system, by default it does not allow you to copy files to or from the system. However, SSH does support this capability through the use of the secure FTP (SFTP) and SSH filesystem (SSHFS) protocols. Once SSH is enabled on a specific system, here is how you can set up and use these protocols.
- Secure FTP
You can access your server through the SFTP protocol similar to how you would access it with a standard FTP client. You have the option for the command-line interface with the "SFTP" command, which runs very similar to the "FTP" command and supports the same "put" and "get" commands for managing files, or you can use a client application like Cyberduck that supports SFTP. This option is likely the easier to manage for most people since client applications can store presets, passwords, and other settings that make your connections easier to do.
- SSH Filesystem
The second option for connecting to SSH services for file transfer is to use the SSHFS protocol, which functions similarly to the Secure FTP protocol but mounts the remote server as a device and presents it to the system and applications as a disk, which can make the connection more seamless. To do this, you will need to install FUSE for OS X, which allows you to use plug-ins for supporting numerous filesystem types instead of relying on native filesystem support in the OS X kernel. In addition, you will need to install the SSHFS module, which is available for download at the FUSE for OS X Web site.
Once FUSE and the SSHFS plug-in are installed, you can establish a connection to your SSH server by running the following command in the Terminal:
sshfs username@hostname:/remote/directory/path /local/mount/point -ovolname=MOUNTNAME
In this command, specify your username and the hostname accordingly, along with the path to the remote folder that you would like to mount. If you use a slash for this folder, then the remote filesystem root will be used, which may be convenient in some cases for full access to the system. The local mount point should be a folder on your system, which can be a folder you create in the system's /Volumes directory or one within your user account. The MOUNTNAME option will be the name of the drive when it is connected, otherwise it will be called something like "OSXFUSE Volume 0 (sshfs)."
As with the SFTP protocol, using the command line to establish the connection may be cumbersome, but fortunately there is a tool called "Macfusion" available that can be used to store common server settings and mount them without needing to type in command options.