Linux: Playing music from another computer or Android phone via SSHFS
Figured I’d share this minor, but nevertheless neat trick that one can do if, like me, they wish to play music stored in another PC (or mobile phone) while working on a Linux system, either in a local network or far away.
Although there are many ways of tackling the same problem, a simple solution is to establish a good old secure shell connection (SSH) to the device where the files are and mount the directory as a local file system.
Afterwards, music players like Rhythmbox (Gnome) or cmus (Terminal) will automatically add the remote files to the local library for playing.
Step 1. Set up Secure Shell (SSH)
If your device is an Android phone, check out SSHelper (ad-free GPL software)
or alternatively Termux (the updated version is available only on F-Droid).
A good way of configuring access to the server that is running remotely is adding its information to ~/.ssh/config
, which should end up looking like:
Host myhost
HostName 192.168.1.XXX
IdentityFile ~/.ssh/id_rsa
User admin
Port 2222
On your remote server, don’t forget to add the contents of your public local key, e.g.~/.ssh/id_rsa.pub
, to the allowlist in ~/.ssh/authorized_keys
.
After that, you may easily log in by running ssh myhost
, or e.g. copy a file to myhost
with scp ~/path/to/input/file myhost:/path/to/output/file
.
Step 2. Mount your remote file system (SSHFS)
From now on, it gets even easier. First, get sshfs
from your distribution’s package manager of choice, if not yet installed, and mount the remote file system containing your music files — considering the previous example:
sshfs -p 2222 myhost:/path/to/Music ~/Music
Provided the SSH connection is working, the remote file system should then become accessible, although file managers like Nautilus won’t always list its contents. To confirm, you may check the output from ls ~/Music
.
Voilà — enjoy playing your remote music library anywhere via SSH.