javaauthenticationconnectionjava-7

not able to authenticate a com.trilead.ssh2.Connection


Heyy!

I am using com.trilead.ssh2.Connection in java 7 to open a connection.

When testing I am opening a connection with localhost on port 22:

Connection connection = new Connection("localhost", 22);

Then I am trying to authenticate with authenticateWithPublicKey method:

char[] key = IOUtils.toString(new FileInputStream("keyLocation")).toCharArray();
boolean authenticated = connection.authenticateWithPublicKey("myUsername", key, "");

But it is not authenticating. I am running on a mac sierra, I'm wondering if that has anything to do. I am using a dsa pair of keys.

Thanks!!


Solution

  • I could not have a work around for dsa pair of keys (i believe it has to do with the key size, and dsa is 1024). I created a new rsa pair of keys with 2048 size. Just as information I'll write the steps for successfully managing to authenticate the connection from the java code configured from my mac sierra:

    I am in the .ssh/ directory:

    ssh-keygen -t rsa -f 'key_name'
    cat key_name.pub                # copy the public key
    # add the public key to authorized_keys file
    ssh-add -K key_name
    ssh-add -A
    ssh-add -l                      # just to check if key is added
    

    and thats it, i managed to authenticate the connection.