Sunday, September 13, 2015

Setting up SSH on Cynogenmod 12.1 for Emacs Tramp

I found the information at https://wiki.cyanogenmod.org/w/Doc:_sshd did not contain enough details for me to be able to be able to do what I wanted, which was to use Tramp from within Emacs.

Setting up the phone for ADB and root access


Unplug phone from USB
Enable "Developer options" settings (tap 7 times on "Settings->About phone->Build number")
Enable Android debugging over USB (Settings->Developer Options->Android debugging)
Enable root for ADB (Settings->Developer Options->Root access, "Apps and ADB" or "ADB only")
Plug in phone via USB
Choose to "Allow android debugging", and hit "Ok".

(Setting up adb is beyond the scope of these instructions.)

Run, "adb devices" to confirm the device can be seen.

adb root
adb push ~/.ssh/id_rsa.pub /data/.ssh/authorized_keys
adb shell


(the following commands are all run in the root shell via ADB)
chmod 640 /data/.ssh/authorized_keys
chown root:shell /data/.ssh/authorized_keys

mkdir -p /data/ssh/empty
chmod -R 700 /data/ssh

cat /system/etc/ssh/sshd_config | \
        sed 's/#PermitRootLogin yes$/PermitRootLogin no/' | \
        sed 's/#PubkeyAuthentication yes/PubkeyAuthentication yes/' | \
        sed 's/#PasswordAuthentication yes/PasswordAuthentication no/' | \
        sed 's/#PermitEmptyPasswords no/PermitEmptyPasswords no/' | \
        sed 's/#ChallengeResponseAuthentication yes/ChallengeResponseAuthentication no/' | \
        sed 's;/usr/libexec/sftp-server;internal-sftp;' > \
        /data/ssh/sshd_config
chmod 600 /data/ssh/sshd_config

cat /system/bin/start-ssh | \
 sed 's;/system/etc/ssh/sshd_config;/data/ssh/sshd_config;' > \
 /data/local/start-ssh
chmod 755 /data/local/start-ssh

exit

Starting SSH

adb root
adb shell /data/local/start-ssh &

At this point the phone can be unplugged and SSH should still be running.

Setting up Tramp

(add-to-list 'tramp-connection-properties
             (list (regexp-quote "192.168.1.9") "remote-shell" "/system/xbin/bash"))
(add-to-list 'tramp-remote-path 'tramp-own-remote-path)
(add-to-list 'tramp-remote-path "/system/xbin")
(add-to-list 'tramp-remote-process-environment "TMPDIR=/data/local/tmp")
(add-to-list 'tramp-remote-process-environment "ANDROID_ROOT=/system") 
 

Setting up $HOME/.ssh/config

Make "shell" the default user for this host.

Host 192.168.1.9
User shell

No comments:

Post a Comment