Gradle脚本SSH部署Oracle Cloud Ubuntu服务器遇JSch Auth fail异常
Gradle SSH部署Oracle Cloud Ubuntu服务器遇Auth fail异常
使用Gradle脚本通过SSH连接Oracle Cloud的Ubuntu服务器部署JWT认证服务时,持续触发以下异常:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':deploy'. com.jcraft.jsch.JSchException: Auth fail
部署任务代码
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() } } } }
已尝试的解决方案
- 确认私钥以
-----BEGIN RSA PRIVATE KEY-----开头,符合JSch要求; - 核对连接凭证与Putty连接时完全一致;
- 确认对应公钥已正确添加至服务器
~/.ssh/authorized_keys; - 更换多台服务器及多组密钥对测试,问题依旧;
- 修改
sshd_config将PasswordAuthentication设为yes(默认值为no)
内容的提问来源于stack exchange,提问作者randomdude0
相关产品推荐
相关产品推荐

