Skip to content

Sataros221/Musync

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

Local Music Sync with SSH + Rsync (Windows + Android Termux)

This guide documents the exact setup for building: syncing music files locally between an Android phone and a Windows PC using SSH + rsync, without Wi‑Fi LAN, without WSL, and without cloud services.

The phone provides internet via hotspot, and the connection is initiated from the phone to the PC.


0. Architecture (Why It Works)

Android hotspot blocks incoming connections to the phone, but allows outgoing connections.

Warning

Using SSH Connection attempts from the PC are blocked when using the phone’s hotspot due to Android’s hotspot firewall.

So this is the right approach:

Phone ──SSH + rsync──▶ PC

Therefore:

  • Windows runs OpenSSH Server

  • Android (Termux) runs SSH client + rsync

  • rsync is executed from the phone


1. Windows: Install and Enable OpenSSH Server

Open PowerShell as Administrator.

Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
Start-Service sshd
Set-Service -Name sshd -StartupType Automatic

Add a firewall rule to accept connections

New-NetFirewallRule -Name "OpenSSH-Server-Inbound" -DisplayName "OpenSSH Server (Inbound)" -Enabled True -Direction Inbound -Protocol TCP -LocalPort 22 -Action Allow

Verify the service:

Get-Service sshd

Test the connection:

ssh localhost

Note

Authentication If it asks for a password, use your Windows account password. If that doesn't work, the next section includes a key-based workaround.


2. Windows: SSH Authorized Keys

2.1 Obtain a Public Key

To obtain a key to grant access to yourself run:

ssh-keygen -t ed25519 -C "yourUserName@localhost"

This will prompt for a passphrase, just press enter twice, so you now have a public and private key in:

C:\Users\yourUser\.ssh

With this two files:

id_ed25519
id_ed25519.pub

may be more but the id_ed25519.pub are the one that we gonna use, now open the file and copy all

ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBASE64DATA YourUserName@localhost

All in one line

2.2 Setting the Key

Windows OpenSSH ships with this rule enabled by default:

Match Group administrators
       AuthorizedKeysFile __PROGRAMDATA__/ssh/administrators_authorized_keys

If your user is in Administrators (most personal PCs):

  • C:\Users\<you>\.ssh\authorized_keys is ignored

  • Keys MUST be placed in:

C:\ProgramData\ssh\administrators_authorized_keys
  • If you don't have the file, create it, notice that the file doesn't have an extension

  • Paste your public key in the file, all in one line

  • Restart the SSH service using:

 Restart-Service sshd
  • Try to connect to ssh localhost again. (It should connect without asking for password)

2.3 If You Still Have Problems

Without correct ACLs, Windows OpenSSH will silently reject keys.

icacls C:\ProgramData\ssh\administrators_authorized_keys /inheritance:r
icacls C:\ProgramData\ssh\administrators_authorized_keys /grant "Administrators:(F)"
icacls C:\ProgramData\ssh\administrators_authorized_keys /grant "SYSTEM:(F)"

Restart SSH:

Restart-Service sshd

3. Android (Termux): Install Required Packages

Install Termux from Play Store, then:

pkg update
pkg install openssh rsync

4. Android (Termux): Generate Public SSH Key

Execute:

ssh-keygen -t ed25519

Your public key:

cat ~/.ssh/id_ed25519.pub

and repeat the process with the Windows one.


5. Android → Windows: Network Preconditions

  • Enable hotspot on the phone

  • Connect the PC to it

  • Determine PC IP address (on Windows):

ipconfig

Example:

IPv4 Address: 192.168.57.195

9. Android: Test SSH to Windows

From Termux:

ssh <windows_user>@192.168.57.195

Expected:

  • No password

  • Successful login


10. Rsync: Sync Music from Phone to PC

Example paths:

  • Phone music:
/storage/emulated/0/Music/
  • PC destination:
C:/Users/<windows_user>/Music/

Run from Termux:

rsync -av --delete \
  /storage/emulated/0/Music/ \
  <windows_user>@192.168.57.195:/c/Users/<windows_user>/Music/

Warning

Command not recognized on Windows Windows doesn't have rsync by default, you must to install it using something like MSYS2 and running

pacman -Syu
pacman -Su
pacman -S rsync

And add the route to the path:

setx /M PATH "%PATH%;C:\msys64\usr\bin"

Flags Explained

  • -a : archive (permissions, timestamps)

  • -v : verbose

  • --delete : remove files deleted on the phone

  • --exclude : excludes folders or files from checking

  • --inplace : writes the updated data directly to the existing destination file

  • --progress : This provides a breakdown for each file, including:

    • File size and current transfer percentage (e.g., 12.3M 100%)
    • Transfer speed (e.g., 86.15MB/s)
    • Estimated time remaining for that specific file (e.g., 0:00:00)
    • A "to-check" statistic, showing how many files are left to process out of the total file list

11. Scripts in This Repo

This repo includes two helper scripts:

  • sync_music.sh (run on Android / Termux)

    • Builds a SHA-256 index for the phone library.
    • Uses a local cache (size + mtime) to avoid re-hashing unchanged files.
    • Syncs files to the PC with rsync, then uploads musica.sha256 into .index/ on the destination.
  • Verify-Music.psm1 (run on Windows / PowerShell)

    • Verifies the files on the PC against .index\musica.sha256.
    • Writes a timestamped snapshot of current hashes into .snapshots\.

11.1 Run the Android sync (Termux)

Tip

Filesystem paths (MSYS2/Cygwin vs Windows) The example destinations use MSYS2-style paths like /d/Music.

From Termux, in the folder where sync_music.sh lives:

chmod +x ./sync_music.sh

# Required (example)
DST="<windows_user>@<pc_ip>:/d/Music" \
  SRC="/storage/emulated/0/Music" \
  ./sync_music.sh

Useful options:

# Show progress every 50 files
DST="<windows_user>@<pc_ip>:/d/Music" PROGRESS_EVERY=50 ./sync_music.sh

# Print cache-hit lines (very verbose)
DST="<windows_user>@<pc_ip>:/d/Music" DEBUG=1 ./sync_music.sh

Notes:

  • DST must be in rsync remote format: user@host:/absolute/or/msys-path.

  • The script uploads musica.sha256 to DST/.index/ (make sure that folder exists on the PC side).


11.2 Verify on Windows (PowerShell)

In PowerShell, from the repo folder:

Import-Module .\Verify-Music.psm1 -Force
# Default base path is your Windows "Music" folder
Invoke-VerifyMusic
# Or specify the destination folder explicitly
Invoke-VerifyMusic -PathBase 'D:\Music'

Telemetry options:

# Print a progress line every 50 entries
Invoke-VerifyMusic -PathBase 'D:\Music' -ProgressEvery 50
# Print OK lines too (very verbose)
Invoke-VerifyMusic -PathBase 'D:\Music' -Details

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors