Skip to content

Instantly share code, notes, and snippets.

@gwenhael-le-moine
Created August 4, 2013 11:58
Show Gist options
  • Save gwenhael-le-moine/6150136 to your computer and use it in GitHub Desktop.
Save gwenhael-le-moine/6150136 to your computer and use it in GitHub Desktop.
As it says, this script will setup a working configuration to run CM10 (minimum)'s included sshd. It doesn't starts it automatically by default as I prefer to control it using Tasker rules but feel free to uncomment the last 2 lines
#!/system/xbin/bash
# Insipred by http://alainwolf.ch/en/tech-talk/ssh-cyanogenmod/
if [ "$UID" != "0" ]; then
echo "This script _MUST_ be run as root"
exit 1
fi
#creates /data/ssh/ if it doesn't exist
mkdir -p /data/ssh/
#known good config
cat <<EOF > /data/ssh/sshd_config
AuthorizedKeysFile /data/ssh/authorized_keys
ChallengeResponseAuthentication no
PasswordAuthentication no
PermitRootLogin without-password
#Subsystem sftp /data/ssh/sftp-server
pidfile /data/ssh/sshd.pid
EOF
#creates an empty authorized_keys file if there isn't any
touch /data/ssh/authorized_keys
#apply correct ownership and permissions otherwise sshd won't start
chown root:root /data/ssh/authorized_keys
chmod 600 /data/ssh/authorized_keys
chmod 644 /data/ssh/sshd_config
#Generate keys if there isn't any
ssh-keygen -A
#scripts to start and stop sshd
cat <<EOF > /data/ssh/sshd-start.sh
#!/system/xbin/bash
#we leverage on the system's script, just changing the sshd_config file used
cp /system/bin/start-ssh /data/ssh/system-start-ssh
sed -i 's|/system/etc/ssh/sshd_config|/data/ssh/sshd_config|g' /data/ssh/system-start-ssh
exec /data/ssh/system-start-ssh
EOF
cat <<EOF > /data/ssh/sshd-stop.sh
#!/system/xbin/bash
if [ -e /data/ssh/sshd.pid ]; then
kill \$(cat /data/ssh/sshd.pid)
rm /data/ssh/sshd.pid
fi
EOF
chmod 755 /data/ssh/sshd-start.sh /data/ssh/sshd-stop.sh
## Uncomment the next 2 lines if you wish sshd to be started at boot time
#mkdir -p /data/local/userinit.d/
#ln -s /data/ssh/sshd-start.sh /data/local/userinit.d/90sshd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment