[Android Q&A, Help & Troubleshooting] smartdog_1:
Hi,

sshd won't work on my htc m7 with cm-12.1

Can anyone help me?

Logcat:

I/sshd ( 9286): debug1: sshd version OpenSSH_6.4, OpenSSL 1.0.1j 15 Oct 2014
W/libc ( 9287): void endpwent()(3) is not implemented on Android
I/sshd ( 9286): void endpwent()(3) is not implemented on Android
I/sshd ( 9286): debug1: read PEM private key done: type RSA
I/sshd ( 9286): debug1: private host key: #0 type 1 RSA
I/sshd ( 9286): debug1: read PEM private key done: type DSA
I/sshd ( 9286): debug1: private host key: #1 type 2 DSA
I/sshd ( 9286): debug1: could not open key file '/data/ssh/ssh_host_ecdsa_key': No such file or directory
I/sshd ( 9286): Could not load host key: /data/ssh/ssh_host_ecdsa_key
I/sshd ( 9286): debug1: rexec_argv[0]='/system/bin/sshd'
I/sshd ( 9286): debug1: rexec_argv[1]='-f'
I/sshd ( 9286): debug1: rexec_argv[2]='/system/etc/ssh/sshd_config'
I/sshd ( 9286): debug1: rexec_argv[3]='-D'
I/sshd ( 9286): debug1: rexec_argv[4]='-d'
I/sshd ( 9286): Set /proc/self/oom_score_adj from 0 to -1000
I/sshd ( 9286): debug1: Bind to port 22 on ::.
I/sshd ( 9286): Server listening on :: port 22.
I/sshd ( 9286): debug1: Bind to port 22 on 0.0.0.0.
I/sshd ( 9286): Server listening on 0.0.0.0 port 22.
I/sshd ( 9286): debug1: Server will not fork when running in debugging mode.
I/sshd ( 9286): debug1: rexec start in 5 out 5 newsock 5 pipe -1 sock 8
D//system/bin/sshd( 9287): debug1: sshd version OpenSSH_6.4, OpenSSL 1.0.1j 15 Oct 2014
W/libc ( 9287): void endpwent()(3) is not implemented on Android
I/sshd ( 9286): void endpwent()(3) is not implemented on Android
D//system/bin/sshd( 9287): debug1: read PEM private key done: type RSA
D//system/bin/sshd( 9287): debug1: private host key: #0 type 1 RSA
D//system/bin/sshd( 9287): debug1: read PEM private key done: type DSA
D//system/bin/sshd( 9287): debug1: private host key: #1 type 2 DSA
D//system/bin/sshd( 9287): debug1: could not open key file '/data/ssh/ssh_host_ecdsa_key': No such file or directory
E//system/bin/sshd( 9287): error: Could not load host key: /data/ssh/ssh_host_ecdsa_key
I/sshd ( 9286): debug1: inetd sockets after dupping: 3, 3
I/sshd ( 9286): Connection from 192.168.156.70 port 46070
I/sshd ( 9286): debug1: Client protocol version 2.0; client software version OpenSSH_6.4
I/sshd ( 9286): debug1: match: OpenSSH_6.4 pat OpenSSH*
I/sshd ( 9286): debug1: Enabling compatibility mode for protocol 2.0
I/sshd ( 9286): debug1: Local version string SSH-2.0-OpenSSH_6.4
I/sshd ( 9286): debug1: permanently_set_uid: 2000/2000 [preauth]
I/sshd ( 9286): debug1: list_hostkey_types: ssh-rsa,ssh-dss [preauth]
I/sshd ( 9286): debug1: SSH2_MSG_KEXINIT sent [preauth]
I/sshd ( 9286): debug1: SSH2_MSG_KEXINIT received [preauth]
I/sshd ( 9286): debug1: kex: client->server aes128-ctr hmac-md5-etm@openssh.com none [preauth]
I/sshd ( 9286): debug1: kex: server->client aes128-ctr hmac-md5-etm@openssh.com none [preauth]
I/sshd ( 9286): debug1: expecting SSH2_MSG_KEX_ECDH_INIT [preauth]
I/sshd ( 9286): debug1: SSH2_MSG_NEWKEYS sent [preauth]
I/sshd ( 9286): debug1: expecting SSH2_MSG_NEWKEYS [preauth]
I/sshd ( 9286): debug1: SSH2_MSG_NEWKEYS received [preauth]
I/sshd ( 9286): debug1: KEX done [preauth]
I/sshd ( 9286): debug1: userauth-request for user root service ssh-connection method none [preauth]
I/sshd ( 9286): debug1: attempt 0 failures 0 [preauth]
I/sshd ( 9286): Connection closed by 192.168.156.70 [preauth]
I/sshd ( 9286): debug1: monitor_read_log: child log fd closed
I/sshd ( 9286): debug1: do_cleanup
I/sshd ( 9286): debug1: Killing privsep child 9313
I/sshd ( 9286): sshd terminated by exit(255)

script: start-ssh

#!/system/bin/sh

umask 077

DEBUG=1

DSA_KEY=/data/ssh/ssh_host_dsa_key
DSA_PUB_KEY=/data/ssh/ssh_host_dsa_key.pub
RSA_KEY=/data/ssh/ssh_host_rsa_key
RSA_PUB_KEY=/data/ssh/ssh_host_rsa_key.pub
AUTHORIZED_KEYS=/data/.ssh/authorized_keys
OLD_AUTHORIZED_KEYS=/data/ssh/authorized_keys
DEFAULT_AUTHORIZED_KEYS=/system/etc/security/authorized_keys.default

if [ ! -f $DSA_KEY ]; then
ssh-keygen -t dsa -f $DSA_KEY -N ""
chmod 600 /$DSA_KEY
chmod 644 $DSA_PUB_KEY
fi

if [ ! -f $RSA_KEY ]; then
/system/bin/ssh-keygen -t rsa -f $RSA_KEY -N ""
chmod 600 /$RSA_KEY
chmod 644 $RSA_PUB_KEY
fi

if [[ -f $OLD_AUTHORIZED_KEYS && ! -f $AUTHORIZED_KEYS ]]; then
cat $OLD_AUTHORIZED_KEYS > $AUTHORIZED_KEYS
fi

if [[ ! -f $AUTHORIZED_KEYS && -f $DEFAULT_AUTHORIZED_KEYS ]]; then
cat $DEFAULT_AUTHORIZED_KEYS > $AUTHORIZED_KEYS
fi

if [ "1" == "$DEBUG" ] ; then
# run sshd in debug mode and capture output to logcat
/system/bin/logwrapper /system/bin/sshd -f /system/etc/ssh/sshd_config -D -d
else
# don't daemonize - otherwise we can't stop the sshd service
/system/bin/sshd -f /system/etc/ssh/sshd_config -D
fi

sshd_config:

#	$OpenBSD: sshd_config,v 1.90 2013/05/16 04:09:14 dtucker Exp $

# This is the sshd server system-wide configuration file. See
# sshd_config(5) for more information.

# This sshd was compiled with PATH=/usr/bin:/bin:/usr/sbin:/sbin

# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented. Uncommented options override the
# default value.

#Port 22
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::

# The default requires explicit activation of protocol 1
#Protocol 2

# HostKey for protocol version 1
#HostKey /etc/ssh/ssh_host_key
# HostKeys for protocol version 2
#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_dsa_key
#HostKey /etc/ssh/ssh_host_ecdsa_key

# Lifetime and size of ephemeral version 1 server key
#KeyRegenerationInterval 1h
#ServerKeyBits 1024

# Ciphers and keying
#RekeyLimit default none

# Logging
# obsoletes QuietMode and FascistLogging
#SyslogFacility AUTH
LogLevel INFO

# Authentication:

#LoginGraceTime 2m
PermitRootLogin without-password
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

RSAAuthentication yes
PubkeyAuthentication yes

# The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2
# but this is overridden so installations will only check .ssh/authorized_keys
#AuthorizedKeysFile	.ssh/authorized_keys
AuthorizedKeysFile	/data/.ssh/authorized_keys

#AuthorizedPrincipalsFile none

#AuthorizedKeysCommand none
#AuthorizedKeysCommandUser nobody

# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
#RhostsRSAAuthentication no
# similar for protocol version 2
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# RhostsRSAAuthentication and HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes

# To disable tunneled clear text passwords, change to no here!
PasswordAuthentication no
#PermitEmptyPasswords no

# Change to no to disable s/key passwords
ChallengeResponseAuthentication no

# Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no

# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes

# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication. Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
#UsePAM no

#AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no
#X11Forwarding no
#X11DisplayOffset 10
#X11UseLocalhost yes
#PrintMotd yes
#PrintLastLog yes
#TCPKeepAlive yes
#UseLogin no
UsePrivilegeSeparation sandbox	# Default for new installations.
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#UseDNS yes
#PidFile /var/run/sshd.pid
#MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none

# no default banner path
#Banner none

# override default of no subsystems
Subsystem	sftp	internal-sftp

# Example of overriding settings on a per-user basis
#Match User anoncvs
#	X11Forwarding no
#	AllowTcpForwarding no
#	ForceCommand cvs server

phone file list:

root@m7:/data/ssh # ls -al
-rwxrwxrwx root root 396 2017-01-18 10:31 authorized_keys
drwx------ root root 2017-01-18 09:05 empty
-rwxrwxrwx 400 root 668 2017-01-18 10:50 ssh_host_dsa_key
-rwxrwxrwx 400 root 604 2017-01-18 10:50 ssh_host_dsa_key.pub
-rwxrwxrwx 400 root 1679 2017-01-18 10:31 ssh_host_rsa_key
-rwxrwxrwx 400 root 396 2017-01-18 10:31 ssh_host_rsa_key.pub
root@m7:/data/ssh # ls -al ../.ssh/
-rw------- root root 396 2017-01-18 10:31 authorized_keys
-rw-r--r-- root root 396 2017-01-18 10:31 known_hosts
root@m7:/data/ssh # start-ssh