'Unable to authorise using jsch private key

I am trying to connect to a local ssh for testing purposes.

I am trying to login using ssh keys with jsch.

This is what I am putting in config:

config.put(STRICT_HOST_KEY_CHECK, strictHostKeyCheckValue); // no config.put("PreferredAuthentications", "publickey");

The keys are valid and I am passing in the correct path to them.

The sever is running in background. But I am not able to connect to it. The error is “Auth failed”. Can anyone suggest where should I look further.

I am working on macos.



Solution 1:[1]

I've never used ssh where the client and server are the same host, but I just tried. The server STILL uses ~/.ssh/authorized_keys to look for the public key. IS it there? Make sure with cat ~/.ssh/id_rsa.pub >>~/.ssh/authorized_keys. That at least is what my public key file is. Yours might be different.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 g00se