0

I’m trying to connect to oracle cloud ubuntu server with SSH using gradle script to deploy jwt authentication.

I'm constantly getting this exception :

org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':deploy'. com.jcraft.jsch.JSchException: Auth fail

The gradle deploy task :

task("deploy") {
    dependsOn("clean", "shadowJar")
    ant.withGroovyBuilder {
        doLast {
            val knownHosts = File.createTempFile("knownhosts", "txt")
            val user = "ubuntu"
            val host = "129.159.251.61"
            val key = file("keys/private-key")
            val jarFileName = "com.jwtauth.ktor-jwt-auth-$version-all.jar"
            try {
                "scp"(
                    "file" to file("build/libs/$jarFileName"),
                    "todir" to "$user@$host:/root/jwtauth",
                    "keyfile" to key,
                    "trust" to true,
                    "knownhosts" to knownHosts
                )
                "ssh"(
                    "host" to host,
                    "username" to user,
                    "keyfile" to key,
                    "trust" to true,
                    "knownhosts" to knownHosts,
                    "command" to "sudo mv /root/jwtauth/$jarFileName /root/jwtauth/jwtauth.jar"
                )
                "ssh"(
                    "host" to host,
                    "username" to user,
                    "keyfile" to key,
                    "trust" to true,
                    "knownhosts" to knownHosts,
                    "command" to "sudo systemctl stop jwtauth"
                )
                "ssh"(
                    "host" to host,
                    "username" to user,
                    "keyfile" to key,
                    "trust" to true,
                    "knownhosts" to knownHosts,
                    "command" to "sudo systemctl start jwtauth"
                )
            } finally {
                knownHosts.delete()
            }
        }
    }

I'm able to connect to server via putty using the same private key.

Solutions I've already tried so far :

  1. I've checked the the private key format and it starts with : -----BEGIN RSA PRIVATE KEY----- which is corret for Jsch (different exception would be thrown if otherwise..)
  2. I've checked the credentials which are the same as when manually connecting via putty
  3. I've checked if the public key (pair of the same private) is added to "authorized_keys" on server
  4. I've tried to create multiple instances of server with multiple ssh keys pairs -> the same issue always
  5. I've set PasswordAuthentification in sshd_config to yes (default was no)

0 Answers0