简体   繁体   English

使用私钥身份验证来保护FTP

[英]Secure FTP using private key authentication

I am using JSCH library to do a sftp between two servers. 我正在使用JSCH库在两个服务器之间执行sftp。 But, I am unable to load the file into the URL using getResource() , for which I get an error during runtime. 但是,我无法使用getResource()将文件加载到URL ,因此在运行时会出错。 I checked the permissions and they are 600, so we should be able to read it. 我检查了权限,它们是600,所以我们应该可以阅读它。

    JSch jsch = new JSch();
    File file = new File("/home/xxxxxx/.ssh/id_rsa");
    Session session = null;
    URL keyFileURL = null;
    URI keyFileURI = null;
    if (file.exists())
    {
        keyFileURL = SecureFTP.class.getClassLoader().getResource("/home/xxxxxx/.ssh/id_rsa");
        if (keyFileURL == null)
        {
            System.out.println("what");
            throw new RuntimeException("Key file not found in classpath");
        }
    }
  try{
             keyFileURI = keyFileURL.toURI();
    }
    catch(Exception URISyntaxException)
    {
        System.out.println("Wrong URL. LOL");
}



    jsch.addIdentity(new File(keyFileURI).getAbsolutePath());

Is there something I am missing, in loading the resource or the path? 在加载资源或路径时我缺少什么吗?

Why don't you use the File.toURL 为什么不使用File.toURL

File file = new File("/home/dev85adm/.ssh/id_rsa");
if (file.exists()) {
    URL keyFileURL = file.toURL();
    //...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Java中使用私钥身份验证来保护FTP - Secure FTP using private key authentication in java 使用数字证书或私钥对FTP服务器进行FTPSClient身份验证 - FTPSClient authentication to an FTP server using a digital certificate or private key 如何使用私钥身份验证进行SVN签出? - How do I SVN checkout using a Private key authentication? 使用vertx的JWT公/私钥身份验证中的握手 - Handshake in JWT public/private key authentication using vertx 使用Java FTP客户端从ColdFusion 9保护FTP - Secure FTP From ColdFusion 9 Using Java FTP Client Eclipse中的openshift私钥认证失败错误 - Private Key authentication failed error in Eclipse for openshift 使用 docker 设置 ftp.ssh 目录,其中包含公钥/私钥信息 - setup ftp .ssh directory with public/private key info with docker 如何使用 SFTP 使用 Java 的公共私钥身份验证的可靠示例 - Reliable example of how to use SFTP using public private key authentication with Java 使用具有公钥/私钥认证的JSch从远程SFTP服务器接收数据。 任何例子? - Ingesting data from remote SFTP server using JSch with public/private key authentication. Any examples? 两个移动设备之间的安全连接:SSL密钥不是“私有” - Secure connection between two mobile devices: SSL key not 'private'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM