Android shell setup hints
TRAMP uses the adb method to access Android devices. Android devices provide a restricted shell access through an USB connection. The local host must have the adb program installed. Usually, it is sufficient to open the file /adb::/. Then you can navigate in the file system via dired.
Alternatively, applications such as Termux or SSHDroid that run sshd process on the Android device can accept any ssh-based methods provided these settings are adjusted:
shmust be specified for remote shell since Android devices do not provide/bin/sh.shwill then invoke whatever shell is installed on the device with this setting:emacs-lisp(add-to-list 'tramp-connection-properties (list (regexp-quote "192.168.0.26") "remote-shell" "sh"))where ‘
192.168.0.26’ is the Android device’s IP address. (see Setting own connection related information).On the Android device the directory names are prefixed with an application specific prefix, which is
/data/data/com.termux/files/usr/bininstead of/usr/binin theTermuxcase. You must adapt the file names intramp-remote-path, for example via connection-local settings:emacs-lisp(connection-local-set-profile-variables 'tramp-connection-local-termux-profile `((tramp-remote-path . ,(mapcar (lambda (x) (if (stringp x) (concat "/data/data/com.termux/files" x) x)) (copy-tree tramp-remote-path))))) (connection-local-set-profiles '(:application tramp :machine "192.168.0.26") 'tramp-connection-local-termux-profile)When the Android device is not ‘
rooted’, specify a writable directory for temporary files:emacs-lisp(add-to-list 'tramp-connection-properties (list (regexp-quote "192.168.0.26") "tmpdir" "/data/data/com.termux/files/home/tmp"))Open a remote connection with the command C-x C-f /ssh:192.168.0.26#2222: RET, where
sshdis listening on port ‘2222’.To add a corresponding entry to the
~/.ssh/configfile (recommended), use this:Host android HostName 192.168.0.26 User root Port 2222To use the host name ‘
android’ instead of the IP address shown in the previous example, fix the connection properties as follows:emacs-lisp(add-to-list 'tramp-connection-properties (list (regexp-quote "android") "remote-shell" "sh")) (add-to-list 'tramp-connection-properties (list (regexp-quote "android") "tmpdir" "/data/data/com.termux/files/home/tmp")) (connection-local-set-profiles '(:application tramp :machine "android") 'tramp-connection-local-termux-profile)Open a remote connection with the more concise command C-x C-f /ssh:android: RET.