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 :
- 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..)
- I've checked the credentials which are the same as when manually connecting via putty
- I've checked if the public key (pair of the same private) is added to "authorized_keys" on server
- I've tried to create multiple instances of server with multiple ssh keys pairs -> the same issue always
- I've set PasswordAuthentification in sshd_config to yes (default was no)