How to stream media files over SFTP on Ubuntu to your Macbook and iMac


Project Overview

At home I have a Linux machine that serves as my development machine. It’s running on Ubuntu and also stores all my media files.

I realized that I want to be able to stream my media files (mainly music) from my Linux machine to my macbook when working at my balcony or away from my computer.

With this solution I was also able to stream large video files too. So far I’ve only streamed to other computers, but I am planning to also to try and stream videos on my Samsung Smart TV.

Here’s what this project solves for me:

  • Stream video & music to any macbook in my household
  • Allows me to manage files over the local network.
  • Allows me read my eBooks/PDFs over the network
  • Does not require installing any third party media management software (e.g. Plex, Kodi, OwnCloud etc.)

Resources

After doing some research online I found a brilliant answer on AskUbuntu by jtd that served as my main guide for setting up my Ubuntu machine.

To learn more please refer to his answer here: https://askubuntu.com/questions/420652/how-to-setup-a-restricted-sftp-server-on-ubuntu#server

Tutorial Steps

  1. Setup a mediausr user on Ubuntu
  2. Install and setup the OpenSSH Server on Ubuntu
  3. Install and setup OSX FUSE to mount files from Ubuntu to your mac

Step 1 – Setup mediausr user to Ubuntu

Create mediausr

useradd mediausr
sudo su mediausr

Create directory for media and return to your main Ubuntu user

mkdir /home/mediausr/Documents/mediasrv
exit

Add your main Ubuntu user to the mediausr group

sudo usermod -a -G mediausr $YOUR_MAIN_USER

Create a symlink to your main Ubuntu user of the media directory

sudo ln -s /home/mediausr/Documents/mediasrv /home/$YOUR_MAIN_USER/Documents

Step 2 – Install and setup OpenSSH on Ubuntu

Source: https://askubuntu.com/questions/420652/how-to-setup-a-restricted-sftp-server-on-ubuntu#server

Instal OpenSSH Server

sudo apt-get install openssh-server

Backup OpenSSH Configuration

sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.factory-defaults
sudo chmod a-w /etc/ssh/sshd_config.factory-defaults

Open the OpenSSH Configuration in a text editor

⚠️Warning:
I did not implement all the recommended security measures as I am not exposing my network to the internet. I highly recommend to implement all the measures as listed in the source: https://askubuntu.com/questions/420652/how-to-setup-a-restricted-sftp-server-on-ubuntu#server

sudo nano /etc/ssh/sshd_config

Make the following changes to the config file:

  1. Comment out PermitRootLogin without-password
  2. Add line PermitRootLogin no
  3. Comment out Port 22
  4. Add new line Port XXXX. Replace XXXX with your custom port.
  5. Find and set line PasswordAuthentication yes
  6. Add line AllowUsers mediausr to only allow mediausr user to login via ssh.
  7. Save and close the text editor.

Restart the OpenSSH Service

sudo service ssh restart

Step 3 – Install OSX Fuse on macOS

Download and Install Fuse for macOS

  1. Go to https://osxfuse.github.io/
  2. Download the latest stable release
  3. Install FUSE as any other application

Create a folder to mount media files to

mkdir ~/Documents/mediasrv

Mount the media files from your Ubuntu server

sshfs -p XXXX mediausr@192.168.YYY.YYY:/home/mediausr/Documents/mediasrv /Users/$USER/Documents/mediasrc -o defer_permissions -o noappledouble

Make sure to set the correct port and ip of your Ubuntu server.

That’s it! Now you can access the files in your macOS finder. Enjoy!