为什么这个 ssh 密钥文件在 Windows/Filezilla 上工作,而不在 linux/命令行上工作?
我使用名为 mykey.ppk
的密钥成功连接到 Windows 上的 FileZilla,
我正在尝试使用该密钥在 Linux 上的 Jenkins 管道中上传文件。
我根本无法让该文件在 ubuntu 中工作 20:04
我使用 PuttyGen 将文件转换为名为 mykey_open.ppk
的 open-ssh 格式文件,如 https://serverfault.com/questions/1004774/load-key-privkey-ppk-invalid- format (加载 > 转换菜单 > 导出 OpenSSH 文件)
我将文件的权限设置为 600,所有者为 jenkins:jenkins
我输入了以下命令在 putty 上,
ssh -Tv [电子邮件受保护] -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
我还尝试使用 pipeline 命令
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
I successfully connect to FileZilla on Windows with a key named mykey.ppk
I am trying to use that key to upload a file in a Jenkins pipeline on Linux.
I can't get the file to work at all in ubuntu 20:04
I converted the file to an open-ssh format file named mykey_open.ppk
using PuttyGen as indicated in https://serverfault.com/questions/1004774/load-key-privkey-ppk-invalid-format (Load > Conversions menu > Export OpenSSH file)
I set the permissions of the file to 600 with owner jenkins:jenkins
I entered the following command on putty,
ssh -Tv [email protected] -i ./mykey_open.ppk
result:
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).
and also in the Jenkins pipeline:
sh 'ssh -Tv [email protected] -i ./mykey_open.ppk'
which gives:
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
I also tried using the pipeline command
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'
}
which gives
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
找到解决方案:使用
sftp
命令而不是ssh
。但 sftp 通常依赖于交互式命令:您输入
sftp
,然后您会收到sftp>
提示,输入诸如put
、之类的命令get
等。在编程上下文中使用该命令有一个解决方法:
在 Jenkins 管道的特定情况下,这将变为:
Found the solution: use
sftp
command instead ofssh
.But sftp usually relies on interactive commands: you type
sftp
, then you get ansftp>
prompt to enter commands such asput
,get
, etc.There is a workaround for using the command in a programming context:
In the specific case of a Jenkins pipeline, this becomes: