2015-11-04 70 views
0

當我們需要將公鑰添加到授權密鑰時,爲什麼我們使用私鑰進行身份文件驗證sftp傳輸當我們需要將公鑰添加到授權密鑰時,爲什麼我們需要將私鑰用作身份文件進行SFTP傳輸使用JSch

Session session = null; 
ChannelSftp sftpChannel = null; 
JSch jsch = new JSch();   
try 
{ 
    session = jsch.getSession(targetUserId, targetHost, targetPort); 
    session.setConfig("StrictHostKeyChecking", "no"); 

    if(identityFile != null) 
    { 
     jsch.addIdentity(identityFile); 
    } 

    if(targetPassword != null) 
    { 
     session.setPassword(targetPassword); 
    } 

    session.connect(); 

回答

0

SSH公鑰認證是使用非對稱加密。

你有一個密鑰對,其中一個密鑰稱爲私人(身份)和其他公衆。用私鑰加密的內容可以用公鑰解密,反之亦然。因此,服務器需要擁有公鑰才能解密來自您的SSH通信(JSch SSH客戶端)。

閱讀關於Public-key cryptography

相關問題