Search code examples
sshantpasswordsscpopenssh

SSH worked fine but scp fails


I am able to SSH and SCP from my local to the server but when I try to ant deploy; it does not work for me but works for my colleague. I get permission denied error, I am unable to understand if I am able to SSH from my local and also SCP a file from my local to the server, what am I missing.

I am running the following command through my script :

<sshexec host="${scp.hostname}"
                 username="${scp.user}"
         keyfile="${scp.keyfile}"
                 trust="true"
                 command="mkdir -p ${projects.home}/${project.name}/${target.dir}" />

This is the error I see :

com.jcraft.jsch.JSchException: invalid privatekey: [B@481c22e0
    at com.jcraft.jsch.KeyPair.load(KeyPair.java:664)
    at com.jcraft.jsch.KeyPair.load(KeyPair.java:561)
    at com.jcraft.jsch.IdentityFile.newInstance(IdentityFile.java:40)
    at com.jcraft.jsch.JSch.addIdentity(JSch.java:407)
    at com.jcraft.jsch.JSch.addIdentity(JSch.java:367)

I checked the path for getting the key information is .ssh/id_rsa

But my OPENSSH Private key does not start with B@481c22e0 as listed in the error message.

Thanks,


Solution

  • Running this command fixed the issue for me.

    ssh-keygen -p -m pem -f id_rsa