在Java中,换行符和回车符似乎都显示出相同的效果.
char文字\n和\rJava 之间的实际差异是什么?
我正在尝试使用 Kotlin + JSch 建立 SSH 连接,但失败并显示
\n\n\ncom.jcraft.jsch.jSchException:身份验证失败
\n
采取的步骤:
\nssh-keygen -t rsa -m PEM使用(OpenSSH 版本OpenSSH_8.2p1:)生成 SSH 密钥对id_rsa.pub到/home/username/.ssh/authorized_keys服务器上的文件中ssh -i /path/to/id_rsa username@example.host.com\xe2\x80\x93 工作正常import com.jcraft.jsch.JSch\n\nconst val USER = "username"\nconst val HOST = "example.host.com"\nconst val IDENTITY = "/path/to/id_rsa"\n\n\nfun main() {\n val jsch = JSch().apply {\n addIdentity(IDENTITY)\n setKnownHosts("/path/to/known_hosts")\n }\n\n jsch.getSession(USER, HOST)\n .connect()\n}\nRun Code Online (Sandbox Code Playgroud)\n...失败但有异常:
\nimport com.jcraft.jsch.JSch\n\nconst val USER …Run Code Online (Sandbox Code Playgroud) 这是迄今为止的成绩单:
$ sbt new lagom/lagom-scala.g8
[info] Loading global plugins from /Users/abrahma/.sbt/1.0/plugins
[info] Set current project to lagomlife (in build file:/Users/abrahma/Bitbucket/Practice-Scala/LagomLife/)
[info] Set current project to lagomlife (in build file:/Users/abrahma/Bitbucket/Practice-Scala/LagomLife/)
ssh://git@github.com/lagom/lagom-scala.g8.git: Auth fail
Run Code Online (Sandbox Code Playgroud)
我已经通过 GitHub 验证了身份验证:
$ ssh -T git@github.com
Hi agam! You've successfully authenticated, but GitHub does not provide shell access.
Run Code Online (Sandbox Code Playgroud)
还验证了我可以访问相关存储库(即我可以在单独的位置执行以下操作):
git clone ssh://git@github.com/lagom/lagom-scala.g8.git
Run Code Online (Sandbox Code Playgroud)
编辑: fwiw 我能够解决这里的任何根本原因:
git clone ssh://git@github.com/lagom/lagom-scala.g8.git
g8 file:///Users/abrahma/tmp/lagom-scala.g8
Run Code Online (Sandbox Code Playgroud) 我\xe2\x80\x99m 在 Windows 上运行 Apache Netbeans 12,并且我\xe2\x80\x99m 很难使用 SSH 连接连接到我的 github 存储库。\n我强烈地感觉到,这对于 Netbeans 用户来说一直是一个问题很长一段时间。\n到目前为止我\xe2\x80\x99已经尝试过:
\n我正在尝试使用 jenkins 和SSH Pipeline Steps插件运行 ssh 部署。我在 MacOS 上使用 openssh 创建了一个 ssh 密钥。
ssh-keygen -m PEM
Run Code Online (Sandbox Code Playgroud)
然后我使用ssh-copy-id. 使用我的命令行登录效果很好。在 Jenkins 中,我创建了一个新的秘密。
我的管道步骤看起来像这样
stage("Deploy to docker host") {
steps {
script {
withCredentials([sshUserPrivateKey(
credentialsId: "docker-jenkins",
keyFileVariable: 'sshKey',
usernameVariable: 'sshUser'
)]) {
def remote = [:];
remote.name = 'docker-host';
remote.host = '127.0.0.1';
remote.user = sshUser;
remote.identity = sshKey;
remote.allowAnyHosts = true;
sshCommand remote: remote, command: "ls -lrt"
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
当我运行管道时,我得到以下输出。
Executing command on 01-de.docker[127.0.0.1]: ls -lrt sudo: …Run Code Online (Sandbox Code Playgroud)