我使用名为mykey.ppk
的密钥成功连接到Windows上的FileZilla
我正试图使用该密钥在Linux上的Jenkins管道中上传一个文件。
我无法让文件在ubuntu 20:04 中工作
我使用PuttyGen将该文件转换为一个名为mykey_open.ppk
的开放ssh格式文件,如中所示https://serverfault.com/questions/1004774/load-key-privkey-ppk-invalid-format(加载>转换菜单>导出OpenSSH文件(
我与所有者jenkins:jenkins一起将文件的权限设置为600
我在腻子上输入了以下命令,
ssh -Tv myuser@myremote.site.io -i ./mykey_open.ppk
结果:
debug1: Trying private key: ./mykey_open.ppk
Load key "./mykey_open.ppk": Permission denied
debug2: we did not send a packet, disable method
debug1: No more authentication methods to try.
myuser@myremote.site.io : Permission denied (publickey).
以及詹金斯管道:
sh 'ssh -Tv myuser@myremote.site.io -i ./mykey_open.ppk'
它给出:
Transferred: sent 2520, received 2244 bytes, in 0.4 seconds
Bytes per second: sent 7154.6, received 6371.0
debug1: Exit status 1
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 1
Finished: FAILURE
我还尝试使用管道命令
def remote = [:]
remote.name = "myremote"
remote.host = "myremote.site.io"
remote.allowAnyHosts = true
withCredentials([sshUserPrivateKey(keyFileVariable: 'identity', passphraseVariable: '', usernameVariable: 'myuser')]) {
remote.user = userName
remote.identityFile = "mykey_open.ppk"
stage("SSH Steps Rocks!") {
sshPut remote: remote, from: 'myfile.zip', into: '/myremote.site.io/path/to/folder'
}
它给出
java.lang.NullPointerException
at java.base/java.util.Objects.requireNonNull(Objects.java:221)
at com.cloudbees.plugins.credentials.CredentialsProvider.findCredentialById(CredentialsProvider.java:877)
at com.cloudbees.plugins.credentials.CredentialsProvider.findCredentialById(CredentialsProvider.java:855)
at org.jenkinsci.plugins.credentialsbinding.MultiBinding.getCredentials(MultiBinding.java:195)
at org.jenkinsci.plugins.credentialsbinding.impl.SSHUserPrivateKeyBinding.bind(SSHUserPrivateKeyBinding.java:94)
at org.jenkinsci.plugins.credentialsbinding.impl.BindingStep$Execution2.doStart(BindingStep.java:134)
at org.jenkinsci.plugins.workflow.steps.GeneralNonBlockingStepExecution.lambda$run$0(GeneralNonBlockingStepExecution.java:77)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:829)
Finished: FAILURE
找到了解决方案:使用sftp
命令而不是ssh
。
但sftp通常依赖于交互式命令:键入sftp
,然后得到sftp>
提示,输入put
、get
等命令。
在编程环境中使用该命令有一个变通方法:
echo put localfile.txt path/to/local/remotefile.txt | sftp -i keyfile.ppk user@remote.site.address
在Jenkins管道的特定情况下,这变成:
sh 'echo put localfile.txt path/to/local/remotefile.txt | sftp -i keyfile.ppk user@remote.site.address'