Is there an open source SSH server with sufficient rights to mount sdcard or internal storage with r/w permissions

As my N900 broke and the Jolla phone is out of stock I bought an fairphone2.

Now I am trying for several evenings to accomplish a very simple task:

Mounting the internal storage or at least the sdcard of the fp2 in my laptop with sshfs to sync my data over WiFi using git-annex. This was a trivial task on the N900 and the Jolla phone. But it seems impossible to do on an Android phone.
.

I tested it on a fp2

First I tested mounting via USB with the fp2 attached as mass storage device. I found out it is importent to set uid and gid to the IDs of my user and its group respectively when mounting. Here both are 1000.

On my laptop I created a mountpoint:

mkdir /tmp/fp2

And as root mounted the device:

mount -o uid=1000,gid=1000 /dev/sdc1 /tmp/fp2

I changed into the mounting directory and cloned the git-annex repo:

cd /tmp/fp2
git clone ~/Musik/  Music/

Everything worked:

Cloning into 'Music'...
done.

Next I tried to mount the fp2 storage using primitive ftpd.

I launched primitive ftpd and opened its settings menu.

I set the…

Server(s) to be started

  • [ ] FTP and SFTP
  • [ ] FTP only
  • [X] SFTP only

And enabled…

Public Key Authentication

And placed my key into the directory where primitive ftpd expects it:

cp /storage/sdcard1/id_rsa.pub /storage/emulated/0/.ssh/authorized_key.pub

I started primitive ftpd and on my laptop tried to mount the internal storage:

sshfs -o sshfs_debug,gid=1000,uid=1000,IdentityFile=/home/lars/.ssh/id_rsa.pub -p 1234 user@192.168.17.228:/storage/emulated/0/ /tmp/fp2/

Now I tried to clone the git-annex repo

git clone ~/Musik/  Music/
Cloning into 'Music'...
error: could not write config file /tmp/fp2/Music/.git/config: Operation not permitted
error: could not write config file /tmp/fp2/Music/.git/config: Operation not permitted
error: could not write config file /tmp/fp2/Music/.git/config: Operation not permitted
error: could not write config file /tmp/fp2/Music/.git/config: Operation not permitted
error: could not write config file /tmp/fp2/Music/.git/config: Operation not permitted
error: could not write config file /tmp/fp2/Music/.git/config: Operation not permitted
fatal: 'origin' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

The repo cannot be cloned because of insufficient write access.

Next I tried the SSH server that comes with Termux. I installed Termux launched it and ran…

apt update && apt upgrade

…to initialize the package database and upgrade all upgradable packages…

termux-setup-storage

…to ensure that permission to shared storage
is granted to Termux.

apt install openssh

…to install ssh client and server.

I copied the key onto fp2’s sdcard:

cp ~/.ssh/id_rsa.pub /tmp/fp2/

umounted the fp2’s sdcard from the laptop:

umount /tmp/fp2

and detached the USB cable.

On the fp2 I created a .ssh directory:

mkdir /data/data/com.termux/files/home/.ssh

and placed my public key into a file called authorized_keys within this directory:

cat /storage/sdcard1/id_rsa.pub /data/data/com.termux/files/home/.ssh/.ssh/authorized_key.pub

Then I started the SSH server:

sshd

The server listens on port 8022, a user name is not necessary and to connect
you have to know the IP address of the device. Here I use 192.168.17.228.

To test connectivity, on my laptop I connected with the SSH client:

ssh -p 8022 192.168.17.228

And got a prompt like this

-bash-4.3$

Now I mounted the fp2’s internal storage:

sshfs -o sshfs_debug,gid=1000,uid=1000,IdentityFile=/home/lars/.ssh/id_rsa.pub -p 8022 192.168.17.228:storage/shared/ /tmp/fp2/

And tested the permissions:

touch /tmp/fp2/test

which was not very promising

touch: setting times of ‘/tmp/fp2/test’: Permission denied

Now I tried to clone the git-annex repo:

cd /tmp/fp2/
git clone ~/Musik/  Music/

which failed as expected:

Cloning into 'Music'...
error: chmod on /tmp/fp2/Music/.git/config.lock failed: Permission denied
error: chmod on /tmp/fp2/Music/.git/config.lock failed: Permission denied
error: chmod on /tmp/fp2/Music/.git/config.lock failed: Permission denied
error: chmod on /tmp/fp2/Music/.git/config.lock failed: Permission denied
error: chmod on /tmp/fp2/Music/.git/config.lock failed: Permission denied
error: chmod on /tmp/fp2/Music/.git/config.lock failed: Permission denied
fatal: 'origin' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

I also tried to start sshd as root on the fp2. In Termux I did:

su
sshd

which does not work:

sh: sshd: not found

I tried with tsu:

apt install tsu
tsu
sshd

Which also failed:

The program 'sshd' is not installed. Install it by executing:
 apt install openssh

I did as it told me:

apt install openssh

and it replied:

The program 'apt' is not installed. Install it by executing:
 apt install apt

which is the funniest instruction I got from an application since “Press start to shutdown”. (Actually, the later is only funnier because they were serious about it.)

I also tried to install Lil’Debi. But this tried to install some app called supersu or superuser and both failed to complete installation.

Then I did a hard reset of the phone and tried primitive ftp and termux again, just to make sure I did not miss something and to be able to write this all down.

I would love to use SailfishOS, but the community version comes without “alien dalvik” which is the Android emulator which allows to install and use Android apps on SailfishOS. And as far as I know there is no commercial distribution of SailfishOS available.

Here are my questions:

  • Is there an open source SSH server with sufficient rights to mount sdcard or internal storage with r/w permissions?
  • If not - is it technically possible to port e.g. dropbear and give it sufficient permissions to accomplish this task?

I am new to Android. I am a long time Linux user but this seems not to be helpful on Android.

Sorry for the short answer, but I’m a bit in a hurry.

For accessing my Android phones wireless I often used sshdroid, which basically turns your phone to an ssh server.
I never tried to mount the phone via sshfs, but for sure I transferred data via sftp (and synced this way in Krusader), and if I remember right, I also used rsync this way.
So maybe that could be possibility for you.

Every Lollipop due to Android 5 has very restricted access to sdcards. Here on the forum is a detailed description including the solution with an official apk/app that enables sdcards for r/w instead only sdcard_r. I am not sure for your very special case. But everybody including me got writing problems on FP2 without relaxing Android5’s sdcard writing restriction. The app is named like NextSD but this maybe not precise for searching this forum. Writing SDcard however should lead you to the right topic. There is also a procedure to patch the file permissions.xml of FP2.

So this is a path problem. I just ran ‘su’ and ‘echo $PATH’. It does not contain the path to things like ssh, apt-get etc. You need to grab the $PATH before you ‘su’ and then export PATH=‘whatever’

Thanks a lot for the suggestion of using sshfs !
I was having lots of trouble with “samba server”, this one looks way more reliable.
I already followed the guide on this forum to allow sdcard RW access, so I can access it without issue.

One concern though, there’s a security issue because sshdroid only gives root access. Would be safer if you could connect with standard user.

Maybe have a look into Termux. You can install openssh and run a ssh server.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.