java - svnkit + ssh 身份验证错误 (E170001)

标签 java svnkit

我是个新人,但我的代码需要一些帮助。这是:

SVNRepositoryFactoryImpl.setup(); 

    SVNURL url = 
      SVNURL. 
          parseURIEncoded("svn+ssh://xxx"); 
    File keyFile = 
          new File("C://Users/xxxx/Documents/priave_key/private_key.ppk"); 
    System.out.println("PPK file space:"+keyFile.getTotalSpace());
    SVNSSHAuthentication sshCredentials = 
         new SVNSSHAuthentication(Settings.name, keyFile, Settings.pass, 22, false, url, false); 
    System.out.println(sshCredentials.getPrivateKey()==null);
    System.out.println("hasPrivateKey(): "+sshCredentials.hasPrivateKey());
    SVNUserNameAuthentication authorNameCredentials = new SVNUserNameAuthentication(Settings.name, false); 
    SVNPasswordAuthentication passwordCredentials =  new SVNPasswordAuthentication(Settings.name, Settings.pass, false); 

    ISVNAuthenticationManager authManager = 
        new BasicAuthenticationManager(new SVNAuthentication[] { 
                     sshCredentials, 
                     authorNameCredentials, 
                     passwordCredentials}); 
    SVNRepository repository = SVNRepositoryFactory.create(url); 
    repository.setAuthenticationManager(authManager); 

    try { 

        SVNDirEntry info = repository.info("", -1); 
        System.out.println(info); 
    } finally { 
        repository.closeSession(); 
    } 

因此,运行此命令后,我得到以下输出:

PPK file space:107374178304
false
hasPrivateKey(): true
Exception in thread "main" org.tmatesoft.svn.core.SVNAuthenticationException: svn:     E170001: Authentication required for 'xxx@svn+ssh://xxx'
    at     org.tmatesoft.svn.core.internal.wc.SVNErrorManager.authenticationFailed(SVNErrorManager.jav    a:47)
    at     org.tmatesoft.svn.core.internal.wc.SVNErrorManager.authenticationFailed(SVNErrorManager.jav    a:41)
    at 

org.tmatesoft.svn.core.auth.BasicAuthenticationManager.getNextAuthentication(BasicAuthentic    ationManager.java:223)
at     org.tmatesoft.svn.core.internal.io.svn.SVNSSHConnector.open(SVNSSHConnector.java:141)
at org.tmatesoft.svn.core.internal.io.svn.SVNConnection.open(SVNConnection.java:77)
at     org.tmatesoft.svn.core.internal.io.svn.SVNRepositoryImpl.openConnection(SVNRepositoryImpl.j    ava:1252)
at     org.tmatesoft.svn.core.internal.io.svn.SVNRepositoryImpl.info(SVNRepositoryImpl.java:1195)
    at SVNTestNew.main(SVNTestNew.java:40)

我认为这可能是 SVNSSHAuthentication 类的问题,因为它为 getPrivateKey() 提供 null,为 hasPrivateKey() 提供 true。) 或者这是一个错误的想法吗?谁能告诉我这个问题如何解决?

最佳答案

据我所知,您的公钥和私钥不在正确的位置。

如果您使用的是 Linux 机器, 对于私钥,您有默认路径:-

${USER_HOME}/.ssh/abc.rsa or abc.dsa

并且您必须将公钥存储在服务器上:

默认路径:-

${USER_HOME}/.ssh/authorized_keys

您可以在/etc/sshd_config文件中更改路径

关于java - svnkit + ssh 身份验证错误 (E170001),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12321674/

相关文章:

java - 放心地为 HTTPS 请求连接被拒绝

java - Autowiring 存储库为空

java - 如何判断列表是否包含映射键

java - 如何在运行时使用 LambdaMetafactory 访问动态类中的非静态方法

java - 使用 SSL 和证书的 SVNKit 身份验证

java - 从java中的给定路径获取所有子父文件夹

java - 无法使用 SVNKit 提交目录树

java - 使用 svnkit 获取文件的先前修改版本

java - 使用 SVNKit 从 SVN 获取已删除文件的历史记录

svnkit - Subversion 用于版本控制