0

I am trying to copy a private key from my raspberry pi to an SSH Server (my Android phone, via SimpleSSHD app).

I can successfully ssh in to the server from the Pi with:

ssh 192.168.0.123 -p 2222

But when I do, I have to enter a password that the SimpleSSHD app shows on the (Android) screen

From the doc (linked above), I am trying to add a private key so I don't have to enter a password every time I SSH into the server:

If SimpleSSHD does not find an authorized_keys file when a client connects, then it generates a single-use password at that time and displays it in the console log. So the procedure to login the first time is to initiate the ssh connection, then look at the phone and type in the password that is on the screen in the SimpleSSHD app. It is recommended to use that shell session to install the authorized_keys file.

Once authorized_keys exists, only public key authentication is supported. If you screw up your authorized_keys file, use the options menu (upper right) -> Reset Keys.

The default home directory is now the app-private directory, which will generally be something like /data/data/org.galexander.sshd/files...

In the app, it shows that the App-private path is: /data/user/0/org.galexander.sshd/files

So, on my RPi, in a terminal I did:

ssh-keygen

and when I do cat ~/.ssh/id_rsa.pub, I get this output:

ssh-rsa AAAAB2Naz[long string of random letters/numbers]ASDFG pi@raspberrypi

So I know I have created a private key.

Now, in the RPi terminal, I did:

ssh 192.168.0.123 -p 2222

And entered the password the SimpleSSHD app creates. Then, I created the authorized_keys folder in the HOME directory, as the docs linked above state...I think:

mkdir ~/authorized_keys

Now, I think all I need to do is copy the RPi's id_rsa.pub to the SimpleSSHD folder, right?, so I tried this from the RPi terminal:

scp -P 2222 ~/.ssh/id_rsa.pub pi@192.168.0.123:~/authorized_keys/id_rsa.pub

But when I do I get this returned in the RPi Terminal:

id_rsa.pub        0%   0    0.0KB/s --:-- ETAlost connection

What am I doing wrong? I've made sure I have updated openssh-clients, as I saw in this Question

Finally, to note, the SimpleSSHD docs say explicitly Create authorized_keys in the home directory (do not use ssh-copy-id), so I am not using ssh-copy-id.

  • I'm guessing here, but perhaps authorized_keys should be a file that you create by copying the id_rsa.pub file. By creating it first (as a directory) perhaps you disabled password-based authentication (as the guide says "Once authorized_keys exists, only public key authentication is supported. If you screw up your authorized_keys file, use the options menu (upper right) -> Reset Keys.") – steeldriver Mar 13 at 2:24
  • @steeldriver so would I just skip the mkdir part? So should I delete the folder first and just skip to scp ...? – BruceWayne Mar 13 at 2:26
  • That's the way I'm reading it - i.e. scp -P 2222 ~/.ssh/id_rsa.pub pi@192.168.0.123:~/authorized_keys. Yes you would need to delete the folder first. This would also be more consistent with the OpenSSH setup where authorized_keys is a file (albeit inside a ~/.ssh/ subdirectory rather than in the home directory itself). – steeldriver Mar 13 at 2:31
  • @steeldriver this makes so much sense because searching online I always see reference to .ssh, but it seems this app specifically uses another folder. I'll try shortly and get back crosses fingers – BruceWayne Mar 13 at 2:32
  • @steeldriver - So, I SSH'ed in to the SSH Server, then did rm -r ~/authorized_keys to remove the directory. Then, in the Pi terminal, scp -P 2222 ~/.ssh/id_rsa.pub root@192.168.0.123:~/authorized_keys/id_rsa.pub, and then get the notice /data/user/0/org.galexander.sshd/files/authorized_keys/id_rsa.pub: No such file or directory...but I know /data/user/0/org.galexander.sshd/files exists because if I do ls ~/, it changes to that directory... – BruceWayne Mar 13 at 2:48

Your Answer

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

Browse other questions tagged or ask your own question.