I'm connecting from my Android handset to my NAS, using SSH. The private key was generated on my PC and then placed in the sd card folder of the phone. So I'm using the identity flag to tell ssh where to find the key file, so

ssh -i /storage/sdcard/key -p 1000 [email protected]

Every time I try to connect I get the message that "the authenticity of host can't be established". So I am asked whether I want to continue connecting and I have to manually say "yes" every time.

For some the host cannot be added to known_hosts and so I get asked every time to confirm manually. I tried to find ".ssh" on my device but I can't find it.

Failed to add the host to the list of known hosts (/data/.ssh/known_hosts)

Can someone please help?


EDIT: I have manually created /data/.ssh/known_hosts but the problem persists

  • Have you checked the permissions on both, the directory /data/.ssh and the file /data/.ssh/known_hosts to ensure your SSH app can access the directory and write to the file?
    – Izzy
    Oct 5, 2013 at 13:22
  • Izzy, thank you very. It was a permissions issue which now has been solved as I'm running it as su.
    – Guest
    Oct 5, 2013 at 15:50
  • Glad to read! I've summed this up in an answer, including some more details of what I had in mind. You're welcome to "accept" the answer (click the check-mark next to it), as it obviously solved your issue :)
    – Izzy
    Oct 5, 2013 at 16:53
  • There's more than how the question is asked. Actually, since Android uses different accounts for different contexts, merely creating /data/.ssh will not be very good. Either you set minimal permissions and it will work only in one context (e.g. adb shell, one terminal emulator, one tunnel application) or you set broad permissions and any application will be able to read and write your known_hosts which is a security risk. A real solution would be to tell ssh to use a different directory depending on the calling context. I tried environment variables HOME and ANDROID_DATA, fail so far. Sep 8, 2014 at 7:25

1 Answer 1


The reason could be insufficient permissions. An app cannot simply chose to create a directory below /data (other than its own, /data/<package_name>, which is already created by the Android system when the app is being installed). So this was why it failed in the first place.

Even after you used your "root powers" to create the /data/.ssh directory, and put a (most likely empty) known_hosts file there, the issue was probably the same: both where owned by the user who created them (root), and the app might not have been able to enter the directory, let alone to write into the file.

There are two possible solutions to this. The first you chose yourself was granting the app SUPER_USER privileges. If this is fine with you (and you trust the app for that), your issue is gone with that. Of course this requires the app to request the SUPER_USER permission, which it obviously does in your case.

A more restrictive approach would have been granting the correct privileges to the directory and the file, by e.g. chown it to the app's user, or chmod appropriately. If owned by that app, only this app would have access there, which would be the best solution. For this, you would first need to figure out the user, which could be done e.g. using ls -l /data/<package_name> (replace <package_name> with the package name of the app), and then do a chown -R <user>:<group> /data/.ssh.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .