Z Fold 7 Mobile Workflow Setup

Setup documentation for Samsung Galaxy Z Fold 7 (SM_F966U1) with Termux for mobile development workflow.

1. Prerequisites

  • Termux installed from F-Droid (not Play Store)

  • USB debugging enabled

  • Device connected via USB

2. Phase 1: Initial Termux Setup

2.1. On Phone (Termux)

pkg update && pkg upgrade -y
pkg install openssh neovim git

3. Phase 2: SSH Key Transfer

3.1. On Workstation

3.1.1. Check Device Connection

adb devices -l
Expected Output
R3GYB0J7YHY  device usb:5-2 product:q7quew model:SM_F966U1 device:q7q transport_id:10

3.1.2. Prepare SSH Keys

mkdir -p /tmp/ssh-push
cp ~/.ssh/id_ed25519_* ~/.ssh/config /tmp/ssh-push/

3.1.3. Push to Phone

adb push /tmp/ssh-push/ /sdcard/Download/ssh-keys/

3.1.4. Forward SSH Port

adb forward tcp:8022 tcp:8022

3.2. On Workstation: Create Setup Script

Generate the automated setup script and push to phone:

cat > /tmp/ssh-push/setup-ssh.sh << 'EOF'
#!/data/data/com.termux/files/usr/bin/bash
# Z Fold 7 SSH Setup Script

echo "=== Setting up SSH ==="

# Create directories
mkdir -p ~/.ssh/sockets

# Copy keys from sdcard
cp -r /sdcard/Download/ssh-keys/* ~/.ssh/

# Set permissions
chmod 700 ~/.ssh ~/.ssh/sockets
chmod 600 ~/.ssh/id_ed25519_* ~/.ssh/config 2>/dev/null
chmod 644 ~/.ssh/*.pub

echo "=== SSH keys installed ==="
echo ""
echo "Now run these manually:"
echo "  passwd    # Set a password"
echo "  sshd      # Start SSH daemon"
EOF
chmod +x /tmp/ssh-push/setup-ssh.sh

# Push script to phone
adb push /tmp/ssh-push/setup-ssh.sh /sdcard/Download/ssh-keys/

3.3. On Phone (Termux)

3.3.1. Run Setup Script

bash /sdcard/Download/ssh-keys/setup-ssh.sh

3.3.2. Configure SSH Server

# Set password for SSH access
passwd

# Start SSH daemon (listens on port 8022)
sshd

# Grant storage permission (if not already done)
termux-setup-storage

3.4. Connect from Workstation

ssh -p 8022 localhost

3.5. SSH Config Entry (Workstation)

Add to ~/.ssh/config for easy access:

Host fold7
    HostName 10.50.10.142    # Phone's IP (check with ifconfig in Termux)
    Port 8022
    User u0_a361             # Your Termux user (check with whoami)
    IdentityFile ~/.ssh/id_ed25519_d000

Now connect with just ssh fold7.

4. Phase 3: Git Configuration

4.1. On Phone (Termux or via SSH)

git config --global user.name "EvanusModestus"
git config --global user.email "evanusmodestus@domusdigitalis.dev"
git config --global core.editor "nvim"
git config --global init.defaultBranch main

5. Phase 4: Pass/GPG Setup (Sync from Workstation)

The GNU Password Store (pass) uses GPG for encryption. Sync both from workstation.

5.1. Install Pass and GPG

pkg install pass gnupg

5.2. Sync from Workstation

# Sync password store (includes .git for updates)
rsync -avz --progress ~/.password-store fold7:~/

# Sync GPG keys
rsync -avz --progress ~/.gnupg fold7:~/

5.3. Verify Pass Works

pass ls
pass show ARCANA/ssh/github  # Get SSH key passphrase

5.4. Add SSH Key to Agent

# Get passphrase from pass, then add key
pass show -c ARCANA/ssh/github
ssh-add ~/.ssh/id_ed25519_github

# Test GitHub connection
ssh -T git@github.com

6. Phase 5: Repository Sync

6.1. Clone Essential Repos

mkdir -p ~/atelier/_bibliotheca
cd ~/atelier/_bibliotheca

# Clone Principia
git clone git@github.com:EvanusModestus/Principia.git

6.2.1. Prerequisites on Phone

# Install rsync in Termux (required on both sides)
pkg install rsync

6.2.2. Sync Entire Atelier (Initial)

First sync excludes .git for speed, then sync .git separately:

# Sync entire atelier (excludes large/regenerable content)
rsync -avz --progress \
  --exclude='.git' \
  --exclude='node_modules' \
  --exclude='build' \
  --exclude='*.pdf' \
  --exclude='*.docx' \
  ~/atelier fold7:~/

6.2.3. Sync All .git Directories (For Git Pull)

To enable git pull on the phone, sync all .git directories:

# Sync ONLY .git directories for all repos
rsync -avz --progress \
  --include='*/' \
  --include='.git/**' \
  --exclude='*' \
  ~/atelier fold7:~/

This enables git pull in any synced repository.

Without SSH config, use explicit port: rsync -avz -e "ssh -p 8022" …​ user@10.50.10.142:~/

7. Phase 6: Dotfiles & Shell Setup

7.1. Install Fish Shell

pkg install fish
chsh -s fish  # Optional: make fish default shell

7.2. Stow Dotfiles (On Phone)

cd ~/atelier/_projects/personal/dotfiles-optimus

# Remove default configs that would conflict
rm ~/.config/fish/config.fish 2>/dev/null

# Stow base packages
stow -d base -t ~ fish bin gpg git

# Stow shell packages (aliases, functions, atelier shortcuts)
stow -d shell -t ~ aliases atelier functions

# Reload shell
exec fish

7.3. Verify Setup

# Check oh-my-posh prompt is working
oh-my-posh --version

# Test aliases (e.g., principia, netapi, etc.)
type principia

# Test pass
pass ls

8. SSH Keys Reference

Key Purpose Works on Phone

id_ed25519_github

GitHub

Yes

id_ed25519_gitlab

GitLab

Yes

id_ed25519_bitbucket

Bitbucket

Yes

id_ed25519_codeberg

Codeberg

Yes

id_ed25519_gitea

Self-hosted Gitea

Yes

id_ed25519_d000

Home servers (d000)

Yes

id_ed25519_d001

Work servers (d001)

Yes

id_ed25519_sk_rk_*

FIDO2/YubiKey

No (requires hardware)

9. Termux Essential Packages

# Core tools
pkg install openssh git neovim tmux curl wget rsync stow

# Password/encryption
pkg install pass gnupg age

# Shell prompt (IMPORTANT: use pkg, not installer script)
pkg install oh-my-posh

# Development
pkg install python nodejs golang

# Network tools
pkg install nmap netcat-openbsd dnsutils

# Android integration (clipboard, notifications, etc.)
pkg install termux-api
For clipboard (pass show -c, etc.) to work, you must also install the Termux:API companion app from F-Droid.
Install oh-my-posh via pkg install, NOT the official installer. The Linux ARM64 binary is incompatible with Android/Termux (Bionic libc vs glibc).

9.1. Auto-Start sshd on Boot (Termux:Boot)

To SSH into your phone without opening Termux first, install Termux:Boot from F-Droid.

# Create boot script directory
mkdir -p ~/.termux/boot

# Create sshd startup script
echo '#!/data/data/com.termux/files/usr/bin/bash
sshd' > ~/.termux/boot/start-sshd.sh

chmod +x ~/.termux/boot/start-sshd.sh

After installing and opening Termux:Boot once (to enable the boot receiver), sshd will start automatically when the device boots.

Test by rebooting phone, then SSH from workstation without opening Termux: ssh fold7

10. Termux-Specific Fixes

Dotfiles synced from a Linux workstation may need adjustments.

10.1. Fix GPG Config (BZIP2 Not Supported)

If you get gpg: invalid item 'BZIP2' in preference string:

# Remove BZIP2 from GPG preferences (not supported in Termux)
sed -i 's/ BZIP2//g' ~/.gnupg/gpg.conf

10.2. Fix GPG Lock (Stale Lock from Workstation)

If you get gpg: database_open waiting for lock (held by XXXXX):

# Remove stale lock files synced from workstation
rm -f ~/.gnupg/public-keys.d/*.lock ~/.gnupg/.#* ~/.gnupg/public-keys.d/.#*
To prevent this, exclude lock files when syncing: rsync --exclude='.lock' --exclude='.#'

10.3. Fix .zshenv (Cargo Not Installed)

If you get no such file or directory: .cargo/env:

# Make cargo sourcing conditional
sed -i '1s|^\. "$HOME/.cargo/env"|[[ -f "$HOME/.cargo/env" ]] \&\& . "$HOME/.cargo/env"|' ~/.zshenv

10.4. Remove Incompatible Binaries

Synced x86_64 binaries won’t run on ARM64. Remove and reinstall via pkg:

# Remove any bad oh-my-posh binaries (x86_64)
rm -f ~/bin/oh-my-posh ~/.local/bin/oh-my-posh

# Install via pkg (ARM64 native)
pkg install oh-my-posh

10.5. Stow Workflow (IMPORTANT)

Do NOT use --adopt when deploying dotfiles to a new machine. It replaces your dotfiles with the target’s files!
cd ~/atelier/_projects/personal/dotfiles-optimus

# CORRECT: Remove conflicting files first, then stow
rm ~/.config/fish/config.fish 2>/dev/null
stow -d base -t ~ fish bin gpg git

# Stow shell packages (aliases, functions)
stow -d shell -t ~ aliases atelier functions

# Skip ssh if ~/.ssh already configured
# stow -d base -t ~ ssh

If you accidentally use --adopt and overwrite your dotfiles:

# On workstation: restore from git
git -C ~/atelier/_projects/personal/dotfiles-optimus checkout -- base/fish/.config/fish/config.fish

# Then copy to phone
scp ~/atelier/_projects/personal/dotfiles-optimus/base/fish/.config/fish/config.fish fold7:~/.config/fish/

11. Troubleshooting

11.1. SSH Connection Refused

# On phone, ensure sshd is running
sshd

# On workstation, re-forward port
adb forward tcp:8022 tcp:8022

11.2. Permission Denied (publickey)

# Check key permissions on phone
ls -la ~/.ssh/
chmod 600 ~/.ssh/id_ed25519_*

11.3. Storage Access

# Grant Termux storage permission
termux-setup-storage

# Access shared storage
ls ~/storage/shared/Download/

12. Quick Reference Checklist

Use this checklist when setting up a new device:

12.1. On Phone (Termux)

  • pkg update && pkg upgrade -y

  • pkg install openssh git neovim rsync stow pass gnupg fish oh-my-posh

  • passwd (set SSH password)

  • sshd (start SSH daemon)

  • termux-setup-storage (grant storage access)

  • whoami (note username for SSH config)

12.2. On Workstation

  • Add SSH config entry for phone

  • adb push ~/.ssh/id_ed25519_* /sdcard/Download/ssh-keys/

  • rsync -avz --exclude='.git' --exclude='node_modules' ~/atelier fold7:~/

  • rsync -avz --include='/' --include='.git/*' --exclude='*' ~/atelier fold7:~/

  • rsync -avz ~/.password-store ~/.gnupg fold7:~/

12.3. On Phone (Final Setup)

  • Copy SSH keys: cp /sdcard/Download/ssh-keys/* ~/.ssh/ && chmod 600 ~/.ssh/id_ed25519_*

  • Remove default configs: rm ~/.config/fish/config.fish

  • Stow dotfiles: cd ~/atelier/_projects/personal/dotfiles-optimus && stow -d base -t ~ fish bin gpg git

  • Stow shell: stow -d shell -t ~ aliases atelier functions

  • Fix .zshenv if needed (conditional cargo)

  • exec fish and verify prompt

  • pass ls and verify GPG works

  • ssh -T git@github.com and verify git access

  • Daily Worklog

  • Network Analysis Tools (linux-ops) - tcpdump, Wireshark, netcat

  • System Hardening (linux-ops) - Security best practices