Skip to content

Instantly share code, notes, and snippets.

@gturi
Last active November 10, 2024 06:23
Show Gist options
  • Save gturi/d88f628bc7f53cac273b51bf93b25408 to your computer and use it in GitHub Desktop.
Save gturi/d88f628bc7f53cac273b51bf93b25408 to your computer and use it in GitHub Desktop.

Revisions

  1. gturi revised this gist Aug 16, 2024. 1 changed file with 14 additions and 5 deletions.
    19 changes: 14 additions & 5 deletions mount-android-device-over-ssh.md
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@

    ## Install scrcpy

    Scrcpy allows to send keyboard input to the device, its installation is recommended since typing commands in the terminal from Android's keyboard it is quite unconfortable:
    Scrcpy allows to send keyboard input to the device, its installation is recommended since typing commands in the terminal from Android's keyboard it is quite uncomfortable:

    ```bash
    scrcpy -K
    @@ -17,7 +17,7 @@ scrcpy -K
    - run `ssh-keygen -A`
    - run `termux-setup-storage` - this will make the app ask for storage permission
    - run `sshd`
    - run `ifconfig` to know you ip address - look at inet field that looks like 192.168.X.Y
    - run `ifconfig` to know you IP address - look at `inet` field that looks like 192.168.X.Y


    ## Test ssh connection
    @@ -37,9 +37,16 @@ cd /storage/emulated/0
    ls
    ```

    ## Mount android with rclone
    ## Mount android

    ### With rclone

    Run `rclone config` and select `sftp` option and follow the guided setup.

    ```bash
    rclone config
    ```

    Run rclone config and select sftp option and follow the guided setup.

    Performing a minimal setup will produce something like this at `$HOME/.config/rclone`:

    @@ -66,7 +73,9 @@ sudo chown "$user:$user" "$mount_point"
    rclone mount android-ssh:$android_dir "$mount_point" --sftp-ask-password
    ```

    ## Mount android with sshfs
    ### With sshfs (deprecated)

    Unfortunately sshfs is no longer maintained, but the setup script is still left for reference.

    ```bash
    android_dir=/storage/emulated/0
  2. gturi revised this gist Apr 26, 2023. 1 changed file with 31 additions and 2 deletions.
    33 changes: 31 additions & 2 deletions mount-android-device-over-ssh.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    # Mount an Android device on your pc filesystem over ssh

    ### Install scrcpy
    ## Install scrcpy

    Scrcpy allows to send keyboard input to the device, its installation is recommended since typing commands in the terminal from Android's keyboard it is quite unconfortable:

    @@ -37,6 +37,35 @@ cd /storage/emulated/0
    ls
    ```

    ## Mount android with rclone

    Run rclone config and select sftp option and follow the guided setup.

    Performing a minimal setup will produce something like this at `$HOME/.config/rclone`:

    ```
    [ssh-connection-name]
    type = sftp
    host = $android_ip
    port = $port
    ```

    By default rclone will attempt to connect using `ssh-agent`. To connect using a password use `--sftp-ask-password` flag:

    ```bash
    android_dir=/storage/emulated/0
    mount_point=/mnt/android-device

    curr_user="$(whoami)"

    id "$curr_user"

    sudo mkdir "$mount_point"
    sudo chown "$user:$user" "$mount_point"

    rclone mount android-ssh:$android_dir "$mount_point" --sftp-ask-password
    ```

    ## Mount android with sshfs

    ```bash
    @@ -69,7 +98,7 @@ If you want to specify a custom ssh config:
    -F /path/to/.ssh/config
    ```

    ## Stop ssh server
    ## Stop Android ssh server

    ```bash
    pkill sshd
  3. gturi revised this gist Apr 25, 2023. 1 changed file with 7 additions and 7 deletions.
    14 changes: 7 additions & 7 deletions mount-android-device-over-ssh.md
    Original file line number Diff line number Diff line change
    @@ -47,14 +47,14 @@ user="$(whoami)"

    id "$user"

    sudo mkdir $mount_point
    sudo chown "$user:$user" $mount_point
    sudo mkdir "$mount_point"
    sudo chown "$user:$user" "$mount_point"

    sshfs \
    -o idmap="$user" \
    -p $port \
    $android_ip:$android_dir \
    $mount_point
    "$android_ip:$android_dir" \
    "$mount_point"
    ```

    If you need to troubleshoot `sshfs` connection you can add the following options:
    @@ -78,7 +78,7 @@ pkill sshd
    ## Unmount directory

    ```bash
    fusermount -u $mount_point
    sudo umount $mount_point
    sudo rmdir $mount_point
    fusermount -u "$mount_point"
    sudo umount "$mount_point"
    sudo rmdir "$mount_point"
    ```
  4. gturi revised this gist Mar 29, 2023. 1 changed file with 14 additions and 3 deletions.
    17 changes: 14 additions & 3 deletions mount-android-device-over-ssh.md
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,13 @@
    # Mount an Android device on your pc filesystem over ssh

    ### Install scrcpy

    Scrcpy allows to send keyboard input to the device, its installation is recommended since typing commands in the terminal from Android's keyboard it is quite unconfortable:

    ```bash
    scrcpy -K
    ```

    ## Install Termux and setup openssh server

    - Install Termux from Github (or F-Droid) on the phone you want to SSH into. Don't use the Play Store version, it doesn't work
    @@ -11,6 +19,7 @@
    - run `sshd`
    - run `ifconfig` to know you ip address - look at inet field that looks like 192.168.X.Y


    ## Test ssh connection

    ```bash
    @@ -34,13 +43,15 @@ ls
    android_dir=/storage/emulated/0
    mount_point=/mnt/android-device

    id $(whoami)
    user="$(whoami)"

    id "$user"

    sudo mkdir $mount_point
    sudo chown $(whoami):$(whoami) $mount_point
    sudo chown "$user:$user" $mount_point

    sshfs \
    -o idmap=$(whoami) \
    -o idmap="$user" \
    -p $port \
    $android_ip:$android_dir \
    $mount_point
  5. gturi revised this gist Mar 29, 2023. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions mount-android-device-over-ssh.md
    Original file line number Diff line number Diff line change
    @@ -31,15 +31,15 @@ ls
    ## Mount android with sshfs

    ```bash
    android_dir=/storage/emulated/0/Download
    android_dir=/storage/emulated/0
    mount_point=/mnt/android-device

    id $(whoami)

    sudo mkdir $mount_point
    sudo chown $(whoami):$(whoami) $mount_point

    sudo sshfs \
    sshfs \
    -o idmap=$(whoami) \
    -p $port \
    $android_ip:$android_dir \
  6. gturi created this gist Mar 29, 2023.
    73 changes: 73 additions & 0 deletions mount-android-device-over-ssh.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,73 @@
    # Mount an Android device on your pc filesystem over ssh

    ## Install Termux and setup openssh server

    - Install Termux from Github (or F-Droid) on the phone you want to SSH into. Don't use the Play Store version, it doesn't work
    - run `pkg update` and `pkg upgrade`
    - run `passwd` and set up a password
    - run `pkg install openssh`
    - run `ssh-keygen -A`
    - run `termux-setup-storage` - this will make the app ask for storage permission
    - run `sshd`
    - run `ifconfig` to know you ip address - look at inet field that looks like 192.168.X.Y

    ## Test ssh connection

    ```bash
    port=8022
    android_ip=192.168.X.Y
    ssh $android_ip -p $port
    ```

    The last command will prompt to digit the password you have previously entered.
    Usually ssh specifies a username (username@$server_ip), if your ssh client doesn't allow you to not enter a username, just use a blank space or asterisk.

    Once connected, you can display your device internal directory tree as follows:
    ```bash
    cd /storage/emulated/0
    ls
    ```

    ## Mount android with sshfs

    ```bash
    android_dir=/storage/emulated/0/Download
    mount_point=/mnt/android-device

    id $(whoami)

    sudo mkdir $mount_point
    sudo chown $(whoami):$(whoami) $mount_point

    sudo sshfs \
    -o idmap=$(whoami) \
    -p $port \
    $android_ip:$android_dir \
    $mount_point
    ```

    If you need to troubleshoot `sshfs` connection you can add the following options:

    ```bash
    -o debug,sshfs_debug,loglevel=debug
    ```

    If you want to specify a custom ssh config:

    ```bash
    -F /path/to/.ssh/config
    ```

    ## Stop ssh server

    ```bash
    pkill sshd
    ```

    ## Unmount directory

    ```bash
    fusermount -u $mount_point
    sudo umount $mount_point
    sudo rmdir $mount_point
    ```