-2

I am new to security domain and wanted to get understanding of this error I'm getting :

com.jcraft.jsch.JSchException: UnknownHostKey: 127.0.0.1. RSA key fingerprint is a2:39:3f:44:88:e9:1f:d7:d1:71:f4:85:98:fb:90:dc at com.jcraft.jsch.Session.checkHost(Session.java:797) at com.jcraft.jsch.Session.connect(Session.java:342) at com.jcraft.jsch.Session.connect(Session.java:183) at FileTransfer.main(FileTransfer.java:37) Process exited with exit code 0.

what is meant by `unknownHostKey: 127.0.0.1. RSA key

fingerprint is a2:39:3f:44:88:e9:1f:d7:d1:71:f4:85:98:fb:90:dc`

I need to set a file called a known_hosts file, in order to fix this error :

I tried to set-it up like so:

127.0.0.1 

But this doensn't work. Am I misunderstanding what is meant by a known_hosts file?

Caffeinated
  • 109
  • 1
  • 5
  • 4
    lets search for "known_hosts file format". Internet is full of answers. – Jakuje Sep 30 '15 at 20:03
  • You seem to be using the same machine as http://stackoverflow.com/questions/32852906/how-to-resolve-java-unknownhostkey-while-using-jsch-sftp-library . Anyway, get the host rsa_key.pub file of the *server* (in Unix this is `/etc/ssh/ssh_host_rsa_key.pub` but I don't know for Cygwin); it should be one line containing `ssh-rsa`, space, and a long string of nearly all letters and digits. Edit that line to insert `127.0.0.1` (or other host address/name) and a space at the beginning. Store as known_hosts. – dave_thompson_085 Oct 01 '15 at 01:05

1 Answers1

1

Credit for this answer goes to Gilles from the StackExchange Security site, as his/her post explaining known_hosts and authorized_keys files is a good starting point to understanding this component of SSH/SFTP.

See below:


The known_hosts file lets the client authenticate the server, to check that it isn't connecting to an impersonator. The authorized_keys file lets the server authenticate the user.

Server authentication

One of the first things that happens when the SSH connection is being established is that the server sends its public key to the client, and proves (thanks to public-key cryptography) to the client that it knows the associated private key. This authenticates the server: if this part of the protocol is successful, the client knows that the server is who it claims it is.

The client may check that the server is a known one, and not some rogue server trying to pass off as the right one. SSH provides only a simple mechanism to verify the server's legitimacy: it remembers servers you've already connected to, in the ~/.ssh/known_hosts file on the client machine (there's also a system-wide file /etc/ssh/known_hosts). The first time you connect to a server, you need to check by some other means that the public key presented by the server is really the public key of the server you wanted to connect to. If you have the public key of the server you're about to connect to, you can add it to ~/.ssh/known_hosts on the client manually.

By the way, known_hosts can contain any type of public key supported by the SSH implementation, not just DSA (also RSA and ECDSA).

Authenticating the server has to be done before you send any confidential data to it. In particular, if the user authentication involves a password, the password must not be sent to an unauthenticated server.

User authentication

The server only lets a remote user log in if that user can prove that they have the right to access that account. Depending on the server's configuration and the user's choice, the user may present one of several forms of credentials (the list below is not exhaustive).

  • The user may present the password for the account that he is trying to log into; the server then verifies that the password is correct.
  • The user may present a public key and prove that he possesses the private key associated with that public key. This is exactly the same method that is used to authenticate the server, but now the user is trying to prove its identity and the server is verifying it. The login attempt is accepted if the user proves that he knows the private key and the public key is in the account's authorization list (~/.ssh/authorized_keys on the server).
  • Another type of method involves delegating part of the work of authenticating the user to the client machine. This happens in controlled environments such as enterprises, when many machines share the same accounts. The server authenticates the client machine by the same mechanism that is used the other way round, then relies on the client to authenticate the user.
bentek
  • 2,235
  • 1
  • 15
  • 23