Skip to content

Instantly share code, notes, and snippets.

@budgierless
Forked from jaimemrjm/Android_tips.md
Created August 13, 2023 12:30
Show Gist options
  • Save budgierless/837552e8e863b49a790babb0338e4d67 to your computer and use it in GitHub Desktop.
Save budgierless/837552e8e863b49a790babb0338e4d67 to your computer and use it in GitHub Desktop.
Android phone tips: SSH / FTP server (for backup, sync...), Samsung Dex

FTP Server in Android

SSH Server in Android

Termux in a powerful app to run a Linux environment, making possible your Android phone has some applications or tools like a desktop computer. So you could backup your phone content seamlessly without any propietary cloud. You can use the embedded ssh server running at 8022 port.

Install ssh server is easy in Termux: pkg install openssh

Config your SSH config in your computer

Edit your ~/.ssh/config to config the Android phone IP address. For example, I use the alias myphone and my router assigns the 192.168.1.4 IP-address:

host myphone
    Hostname 192.168.1.4
    Port 8022

Config your Android phone

Then in your Android phone, open Termux and execute whoami. Get the user name, and set the password with the command passwd.

(Optionally) Install rsync: pkg install rsync

Then copy your public key from your computer: ssh-copy-id -i ~/.ssh/id_rsa.pub -p 8022 <your_phone_ip>

Backup/Sync your phone files to your computer

  • Start the SSH server from Termux: sshd
  • Get the Android IP network adderss: ip a
  • Rsync from your computer: rsync -rvlc --exclude={thumbnails,.thumbnails,tmfs,.tmfs,trash,.Trash} --delete-excluded myphone:/sdcard <backup_path_in_your_computer>

Disable password authentication (optionally)

To improve security, go to $PREFIX/etc/ssh/ in your phone and modify the sshd_config file (for example, use nano sshd_config) and switch the config line PasswordAuthentication from yes to no.

Alternative connection via USB

If you have no WiFi available (for example, by train/underground/plane...) or you want to improve the connection speed, you can use a USB cable to connect your Android phone via USB to your computer. USB tethering or ADB USB debugging (recommended) are available. Execute: adb forward tcp:8022 tcp:8022 and you will have SSH connectivity in your 8022 port (localhost) to your Android phone:

ssh localhost -p 8022.

How to downgrade an Android without losing data and removing it

# Download the apk before
adb push xyz.apk /data/local/tmp/
adb shell pm install -r -d /data/local/tmp/xyz.apk

Samsung Dex tips

Fixing flickering/disconnecting screen when Desktop Mode on Samsung Dex

It seems WiFi + Power charging + Display on output screen + Mobile Data makes powering issues so disable Mobile Data connection fix the issue (really not needed because typically you can use WiFi or Ethernet interface).

Copy-paste

Copy&paste works mostly in apps but in terminal apps doesn't work Ctrl-v is not correct shortcut for pasting. That's a reserved key combination. In Termux works:

  • Paste: Ctrl+Alt+V

Tip for Termux when Android >= 12L

Run command once to disable killing of phantom processes and processes using excessive cpu (recommeded for Termux in Android 12L or 13):

adb shell "settings put global settings_enable_monitor_phantom_procs false"

Visual Studio Code on Samsung Dex

Install code-server from Termux is easy but have a version that works is not easy:

pkg upgrade -y
pkg install nodejs-lts python yarn binutils
FORCE_NODE_VERSION=FALSE yarn global add [email protected] --ignore-engines;
sed -i -e 's|switch(process.platform)|switch("linux")|' /data/data/com.termux/files/home/.config/yarn/global/node_modules/code-server/lib/vscode/out/vs/platform/terminal/node/ptyHostMain.js

To start:

code-server --auth none 

Reference

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment