2012-09-07 48 views
1

我在这里有点新,但我需要一些帮助,我的代码。那就是:Svnkit + ssh认证错误(E170001)

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 '[email protected]+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) 

我想是因为它给空了getPrivateKey()和真正的hasPrivateKey(这可能是与SVNSSHAuthentication类的问题)或者这是一个错误的想法?谁能告诉我这个问题怎么解决?

回答

0

根据我的你的公钥和私钥不在适当的地方。

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

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

而且你必须在服务器来存储你的公钥:

默认路径: -

${USER_HOME}/.ssh/authorized_keys 

可以在/etc/sshd_config file

改变你的路径