我使用名為的密鑰成功連接到 Windows 上的 FileZillamykey.ppk
我正在嘗試使用該密鑰在 Linux 上的 Jenkins 管道中上傳檔案。
我無法讓檔案在 ubuntu 20:04 中作業
mykey_open.ppk我將檔案轉換為使用 PuttyGen命名的 open-ssh 格式檔案,如https://serverfault.com/questions/1004774/load-key-privkey-ppk-invalid-format中所示 (加載 > 轉換選單 > 匯出 OpenSSH 檔案)
我使用所有者 jenkins:jenkins 將檔案的權限設定為 600
我在膩子上輸入了以下命令,
ssh -Tv [email protected] -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.
[email protected] : Permission denied (publickey).
并且還在 Jenkins 管道中:
sh 'ssh -Tv [email protected] -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
uj5u.com熱心網友回復:
找到解決方案:使用sftpcommand 而不是ssh.
但是 sftp 通常依賴于互動式命令:你輸入sftp,然后你會得到一個sftp>提示輸入命令,比如put,get等等。
在編程背景關系中使用該命令有一個解決方法:
echo put localfile.txt path/to/local/remotefile.txt | sftp -i keyfile.ppk [email protected]
在 Jenkins 管道的特定情況下,這變為:
sh 'echo put localfile.txt path/to/local/remotefile.txt | sftp -i keyfile.ppk [email protected]'
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/436774.html
