Skip to content

Instantly share code, notes, and snippets.

@jaimemrjm
Last active May 30, 2024 08:16
Show Gist options
  • Save jaimemrjm/941dfc7050ca89ae85f4acb106879fd3 to your computer and use it in GitHub Desktop.
Save jaimemrjm/941dfc7050ca89ae85f4acb106879fd3 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

DNS config

Recommended to config a private DNS from a public available one in your country. For example: ControlD Malware+Ads.

Samsung Dex tips

Browser recommended

Samsung Internet Browser includes IA, is fast and optimized for Samsung Dex. The Adguard Content Blocker addon gets a good mark in https://adblock-tester.com/

Alternative browser

Cromite browser plus adblocking userscripts is the best open source alternative for me.

Private DNS config

Recommended private DNS to config:

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

code-server (vscode on browser)

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 code-server@4.6.0 --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 

code-oss (vscode native and opensource)

On termux:

pkg i tur-repo  
pkg i code-oss code-is-code-oss

Reference

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