0

My android 4.4.2 (it is old but can't be upgraded) phone runs a SSH server by SimpleSSHD app. It generates different random password at every login, so is very inconvenient for me as a client user. So I would like to use public key authentication.

Previously I have generated a pair of public and private keys to access a SSH server. I guess it is okay to reuse the key pair, so I copy the public key file to the android phone:

$ ssh-copy-id -p 2222 192.168.1.87
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/t/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
t@192.168.1.87's password: 
restorecon: invalid option -- F
usage:  restorecon [-nrRv] pathname...

After that I still have to type random passwords generated by the server in order to log in.

Does copying the public key file to the android phone not work?

Into which directory on the android phone should the public key file go?

Thanks.

1

This isn't an issue with android. I believe the convention of putting keys in ~/.ssh/authorized_keys is from OpenSSH. I don't believe it's part of the standard (RFCs). SimpleSSHD has a different convention:

Quick start

  • Install SimpleSSHD.
  • On any computer which will connect to your Android device, set the port to 2222. With OpenSSH, this can be done by putting these lines in ~/.ssh/config:

    Host myphone
    Port 2222
    
  • Launch SimpleSSHD, and in Settings enable "Start on Boot", then manually start it for the first time.

  • Create authorized_keys in the home directory (do not use ssh-copy-id)
  • Optionally make .profile

The inference of this is that your authorized keys files should be ~/authorized_keys not ~/.ssh/authorized_keys.

ssh-copy-id appears to assume that every server is an OpenSSH server. Since you have already set your public key using ssh-copy-id, I would just login and run:

mv ~/.ssh/authorized_keys ~
| improve this answer | |
  • Thanks. Is it correct that ~ is a shell-specific setting not an Android-specific setting? ~ is expanded to a ssh server specific path. For comparison, in a shell provided by Terminal Emulator app on Android, I can't type ~ in echo ~. – Tim Nov 22 '19 at 12:44
  • Yes ~ is expanded by the shell. Not sure if this is actually POSIX shell standard, but I know most *nix shells expand it as your home directory. Android shell is one of the standard *nix ones lest time I checked. – Philip Couling Nov 22 '19 at 13:59
  • SimpleSSHD server's shell provides sh, which provides ~. My android locally uses Terminal Emulator app, which doesn't take ~ that I type. – Tim Nov 22 '19 at 14:03
  • My only experience here is logging onto my phone from my pc via adb it's admittedly a few years since I tried. I thought that shell was standard in the is but maybe I'm wrong. – Philip Couling Nov 22 '19 at 14:08
  • 1
    The tilde expansion is not supported in the android shell from before the switch to mksh. Nothing to do with the terminal emulator. Also, ~/authorized_keys instead of ~/.ssh/authorized_keys is not a dropbox thing, it's just peculiar to that SimpleSSHD app, about which the OP better ask its authors, since it apparently does other strange things. – mosvy Nov 25 '19 at 11:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.