使用 SSHJ 和 ed25519 的 SFTP 上传遇到关键问题
SFTP upload using SSHJ and ed25519 experiencing key Issues
我正在尝试使用 ed25519 身份验证设置 SFTP 上传,但我不断收到此错误:
Exception in thread "main" java.lang.UnsupportedOperationException: Don't know how to decode key:ssh-ed25519
这是我的代码:
import java.io.File;
import java.io.IOException;
import net.schmizz.sshj.SSHClient;
import net.schmizz.sshj.sftp.SFTPClient;
import net.schmizz.sshj.userauth.keyprovider.OpenSSHKeyFile;
import net.schmizz.sshj.xfer.FileSystemFile;
import net.schmizz.sshj.transport.verification.PromiscuousVerifier;
String username = "scansionitesz";
String remoteDir = "files";
String remoteFile = "prova_delega.pdf";
String localDir = "C:/Users/VERSIM/Desktop";
final SSHClient ssh = new SSHClient();
ssh.addHostKeyVerifier(new PromiscuousVerifier());
ssh.connect(server);
try {
File privateKey = new File(openSSHPrivateKey);
KeyProvider keys = ssh.loadKeys(privateKey.getPath());
OpenSSHKeyFile key = new OpenSSHKeyFile();
key.init("-----BEGIN OPENSSH PRIVATE KEY-----\n" +
"my_private_key\n" +
"-----END OPENSSH PRIVATE KEY-----",
"ssh-ed25519 my_public_key scansionitesz@tes"
);
ssh.authPublickey(username,key);
final SFTPClient sftp = ssh.newSFTPClient();
try {
sftp.put(new FileSystemFile(localDir + "/" + remoteFile), "/" + remoteDir);
} finally {
sftp.close();
}
} finally {
ssh.disconnect();
}
我错过了什么?
我猜您使用的是一些不支持 Ed25519 密钥的旧版本 sshj。
自 0.15.0(2015 年 11 月)起支持它们。
我正在尝试使用 ed25519 身份验证设置 SFTP 上传,但我不断收到此错误:
Exception in thread "main" java.lang.UnsupportedOperationException: Don't know how to decode key:ssh-ed25519
这是我的代码:
import java.io.File;
import java.io.IOException;
import net.schmizz.sshj.SSHClient;
import net.schmizz.sshj.sftp.SFTPClient;
import net.schmizz.sshj.userauth.keyprovider.OpenSSHKeyFile;
import net.schmizz.sshj.xfer.FileSystemFile;
import net.schmizz.sshj.transport.verification.PromiscuousVerifier;
String username = "scansionitesz";
String remoteDir = "files";
String remoteFile = "prova_delega.pdf";
String localDir = "C:/Users/VERSIM/Desktop";
final SSHClient ssh = new SSHClient();
ssh.addHostKeyVerifier(new PromiscuousVerifier());
ssh.connect(server);
try {
File privateKey = new File(openSSHPrivateKey);
KeyProvider keys = ssh.loadKeys(privateKey.getPath());
OpenSSHKeyFile key = new OpenSSHKeyFile();
key.init("-----BEGIN OPENSSH PRIVATE KEY-----\n" +
"my_private_key\n" +
"-----END OPENSSH PRIVATE KEY-----",
"ssh-ed25519 my_public_key scansionitesz@tes"
);
ssh.authPublickey(username,key);
final SFTPClient sftp = ssh.newSFTPClient();
try {
sftp.put(new FileSystemFile(localDir + "/" + remoteFile), "/" + remoteDir);
} finally {
sftp.close();
}
} finally {
ssh.disconnect();
}
我错过了什么?
我猜您使用的是一些不支持 Ed25519 密钥的旧版本 sshj。
自 0.15.0(2015 年 11 月)起支持它们。