Today, i try to use termux on my one-plus phone.After all set up,
I want to ssh to my phone through my laptop,but no matter what i tried,it show me a wrong message.
ssh [email protected] -p 8022
[email protected]: Permission denied (publickey,keyboard-interactive)
i checked my userid with 'whoami',it's 'u0_a191'.
then i telnet to the phone
telnet 192.168.1.162 8022
Trying 192.168.1.162...
Connected to 192.168.1.162.
Escape character is '^]'.
SSH-2.0-OpenSSH_7.6
Protocol mismatch.
Connection closed by foreign host.
obviously port 8022 is open.
i read the article here https://glow.li/tech/2015/11/06/run-an-ssh-server-on-your-android-with-termux.html
copy the public key to the phone again and change the permission ,but still it does't work.
i can not understand what's wrong with my configure ,here is the sshd debug messages:
sshd -d
debug1: sshd version OpenSSH_7.6, OpenSSL 1.0.2m 2 Nov 2017
debug1: private host key #0: ssh-rsa SHA256:cqUh69k2N5W0ti0IUQmxLauyNTcn+xvID0Jq3iIJhWY
debug1: private host key #1: ssh-dss SHA256:jcVbBQxAA4BlZ1Y6b4p2CpDYypBHlObETGqd9/mc/D0
debug1: private host key #2: ecdsa-sha2-nistp256 SHA256:qMxic5KtJyjNtposmaK3P9y1ziS70JQTZ81az/ssLFU
debug1: private host key #3: ssh-ed25519 SHA256:UfG+7bVB6LhTy/ubQDNthwY2TJ0XT3rIwF35gThFGQI
debug1: rexec_argv[0]='/data/data/com.termux/files/usr/bin/sshd'
debug1: rexec_argv[1]='-d'
debug1: Bind to port 8022 on ::.
Server listening on :: port 8022.
debug1: Bind to port 8022 on 0.0.0.0.
Server listening on 0.0.0.0 port 8022.
debug1: Server will not fork when running in debugging mode.
debug1: rexec start in 5 out 5 newsock 5 pipe -1 sock 8
debug1: inetd sockets after dupping: 5, 5
Connection from 192.168.1.110 port 35190 on 192.168.1.162 port 8022
debug1: Client protocol version 2.0; client software version OpenSSH_7.6
debug1: match: OpenSSH_7.6 pat OpenSSH* compat 0x04000000
debug1: Local version string SSH-2.0-OpenSSH_7.6
debug1: list_hostkey_types: ssh-rsa,rsa-sha2-512,rsa-sha2-256,ecdsa-sha2-nistp256,ssh-ed25519
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: none
debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_INIT
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 134217728 blocks
debug1: KEX done
debug1: userauth-request for user u0_a191 service ssh-connection method none
debug1: attempt 0 failures 0
Failed none for u0_a191 from 192.168.1.110 port 35190 ssh2
debug1: userauth-request for user u0_a191 service ssh-connection method publickey
debug1: attempt 1 failures 0
debug1: userauth_pubkey: test whether pkalg/pkblob are acceptable for RSA SHA256:Aw5kgNa4Fqhz2geOzqCuoD5mdU5dBUXOc9XylATHQGM
debug1: temporarily_use_uid: 10191/10191 (e=10191/10191)
debug1: trying public key file /data/data/com.termux/files/home/.ssh/authorized_keys
debug1: fd 6 clearing O_NONBLOCK
debug1: restore_uid: (unprivileged)
debug1: temporarily_use_uid: 10191/10191 (e=10191/10191)
debug1: trying public key file /data/data/com.termux/files/home/.ssh/authorized_keys2
debug1: Could not open authorized keys '/data/data/com.termux/files/home/.ssh/authorized_keys2': No such file or directory
debug1: restore_uid: (unprivileged)
Failed publickey for u0_a191 from 192.168.1.110 port 35190 ssh2
debug1: userauth-request for user u0_a191 service ssh-connection method keyboard-interactive
debug1: attempt 2 failures 1
debug1: keyboard-interactive devs
debug1: auth2_challenge: user=u0_a191 devs=
debug1: kbdint_alloc: devices ''
Failed keyboard-interactive for u0_a191 from 192.168.1.110 port 35190 ssh2
Connection closed by authenticating user u0_a191 192.168.1.110 port 35190
debug1: do_cleanup
It's quite easy to copy the public key wrongly, please make sure that ~/.ssh/authorized_keys ends with an empty line and that your public key (in that file) doesn't have any line breaks.
@Grimler91 it seems like this problem.But it's too difficult to send the pc public key to my phone(at least i don't find the right way) or edit the copy content from pc(this is where i get the problem, it always copy with wrong format).So i change my mind and generate the private and public key with ssh-keygen in my phone,then i send the information form id_rsa.pub to the authorized_keys.Then send the information form id_rsa to my computer through chat app.
Use this private key i can ssh to my phone successfully.Thank you for your hellp!
@fivestrong I would not recommend sending the private key over any type of potentially unsafe communication (like a chat app).
In this case, I think the easiest way to copy the id_rsa.pub would be to log onto the laptop from the phone, copy the content of id_rsa.pub to the android clipboard and then paste it in authorized_keys (and potentially fix a few line breaks).
Anyways, good that it works!
Now that ssh is working, you could change the key through it or sftp, if you like. I would use the authorized_keys2 file as a backup, and delete it after verifying the change works.
@fornwall Hi! I fixed ssh password authentication on my phone! The details are placed here. Of cource string_hash function can be easily replaced with SSL's MD5 functions. I used it only for example build. Hasher binary can be called like termux-passwd or something. Or just passwd. The choice is yours.
Almost the same thing may be applied to dropbear. There you need to patch svr-authpam.c file.
The fix.
I used the first of the following commands to copy the keys from my computer to my phone:
# Accessing termux user environment from other consoles
# https://android.stackexchange.com/questions/154756/accessing-termux-user-environment-from-other-consoles
scp [email protected]:~/.ssh/id_rsa.pub ~/.ssh/authorized_keys
Later, I find this other one:
# How do I add SSH Keys to authorized_keys file?
# https://askubuntu.com/questions/46424/how-do-i-add-ssh-keys-to-authorized-keys-file
cat ~/.ssh/id_rsa.pub | ssh [email protected] "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"
Just set password, now termux supports password based authentication ,execute
passwd
Enter-new password:
Re-type new password:
Done.
Now try to ssh with username and password on port 8022.
Today, i try to use termux on my one-plus phone.After all set up,
I want to ssh to my phone through my laptop,but no matter what i tried,it show me a wrong message.ssh [email protected] -p 8022 [email protected]: Permission denied (publickey,keyboard-interactive)i checked my userid with 'whoami',it's 'u0_a191'.
then i telnet to the phonetelnet 192.168.1.162 8022 Trying 192.168.1.162... Connected to 192.168.1.162. Escape character is '^]'. SSH-2.0-OpenSSH_7.6 Protocol mismatch. Connection closed by foreign host.obviously port 8022 is open.
i read the article here https://glow.li/tech/2015/11/06/run-an-ssh-server-on-your-android-with-termux.html
copy the public key to the phone again and change the permission ,but still it does't work.i can not understand what's wrong with my configure ,here is the sshd debug messages:
sshd -d debug1: sshd version OpenSSH_7.6, OpenSSL 1.0.2m 2 Nov 2017 debug1: private host key #0: ssh-rsa SHA256:cqUh69k2N5W0ti0IUQmxLauyNTcn+xvID0Jq3iIJhWY debug1: private host key #1: ssh-dss SHA256:jcVbBQxAA4BlZ1Y6b4p2CpDYypBHlObETGqd9/mc/D0 debug1: private host key #2: ecdsa-sha2-nistp256 SHA256:qMxic5KtJyjNtposmaK3P9y1ziS70JQTZ81az/ssLFU debug1: private host key #3: ssh-ed25519 SHA256:UfG+7bVB6LhTy/ubQDNthwY2TJ0XT3rIwF35gThFGQI debug1: rexec_argv[0]='/data/data/com.termux/files/usr/bin/sshd' debug1: rexec_argv[1]='-d' debug1: Bind to port 8022 on ::. Server listening on :: port 8022. debug1: Bind to port 8022 on 0.0.0.0. Server listening on 0.0.0.0 port 8022. debug1: Server will not fork when running in debugging mode. debug1: rexec start in 5 out 5 newsock 5 pipe -1 sock 8 debug1: inetd sockets after dupping: 5, 5 Connection from 192.168.1.110 port 35190 on 192.168.1.162 port 8022 debug1: Client protocol version 2.0; client software version OpenSSH_7.6 debug1: match: OpenSSH_7.6 pat OpenSSH* compat 0x04000000 debug1: Local version string SSH-2.0-OpenSSH_7.6 debug1: list_hostkey_types: ssh-rsa,rsa-sha2-512,rsa-sha2-256,ecdsa-sha2-nistp256,ssh-ed25519 debug1: SSH2_MSG_KEXINIT sent debug1: SSH2_MSG_KEXINIT received debug1: kex: algorithm: curve25519-sha256 debug1: kex: host key algorithm: ecdsa-sha2-nistp256 debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: none debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none debug1: expecting SSH2_MSG_KEX_ECDH_INIT debug1: rekey after 134217728 blocks debug1: SSH2_MSG_NEWKEYS sent debug1: expecting SSH2_MSG_NEWKEYS debug1: SSH2_MSG_NEWKEYS received debug1: rekey after 134217728 blocks debug1: KEX done debug1: userauth-request for user u0_a191 service ssh-connection method none debug1: attempt 0 failures 0 Failed none for u0_a191 from 192.168.1.110 port 35190 ssh2 debug1: userauth-request for user u0_a191 service ssh-connection method publickey debug1: attempt 1 failures 0 debug1: userauth_pubkey: test whether pkalg/pkblob are acceptable for RSA SHA256:Aw5kgNa4Fqhz2geOzqCuoD5mdU5dBUXOc9XylATHQGM debug1: temporarily_use_uid: 10191/10191 (e=10191/10191) debug1: trying public key file /data/data/com.termux/files/home/.ssh/authorized_keys debug1: fd 6 clearing O_NONBLOCK debug1: restore_uid: (unprivileged) debug1: temporarily_use_uid: 10191/10191 (e=10191/10191) debug1: trying public key file /data/data/com.termux/files/home/.ssh/authorized_keys2 debug1: Could not open authorized keys '/data/data/com.termux/files/home/.ssh/authorized_keys2': No such file or directory debug1: restore_uid: (unprivileged) Failed publickey for u0_a191 from 192.168.1.110 port 35190 ssh2 debug1: userauth-request for user u0_a191 service ssh-connection method keyboard-interactive debug1: attempt 2 failures 1 debug1: keyboard-interactive devs debug1: auth2_challenge: user=u0_a191 devs= debug1: kbdint_alloc: devices '' Failed keyboard-interactive for u0_a191 from 192.168.1.110 port 35190 ssh2 Connection closed by authenticating user u0_a191 192.168.1.110 port 35190 debug1: do_cleanup
It's quite easy to copy the public key wrongly, please make sure that ~/.ssh/authorized_keys ends with an empty line and that your public key (in that file) doesn't have any line breaks.
Now termux supports password bases authentication.
:D
Wow it started working after I changed the password using: passwd
Most helpful comment
It's quite easy to copy the public key wrongly, please make sure that ~/.ssh/authorized_keys ends with an empty line and that your public key (in that file) doesn't have any line breaks.