DSA 秘密鍵または公開鍵 (公開鍵は秘密鍵から生成されています) を使用して ssh 経由でリモート サーバーに接続したいのですが、次のエラーが発生します。
Disconnecting with error, code 14 reason: no more authentication methods available
これが私のスクリプトです(Twisted Conch):
#!/usr/bin/env python
from twisted.conch import error
from twisted.internet import defer, protocol, reactor
from twisted.conch.ssh import keys, userauth, connection, transport, channel, common
from twisted.python import log
import sys
class ClientTransport(transport.SSHClientTransport):
def verifyHostKey(self, pubKey, fingerprint):
return defer.succeed(1)
def connectionSecure(self):
self.requestService(ClientUserAuth('myusername', ClientConnection()))
private_key_file = "key_priv"
public_key_file = "key_pub"
class ClientUserAuth(userauth.SSHUserAuthClient):
def getPassword(self, prompt=None):
return
def getPublicKey(self):
return keys.Key.fromFile(public_key_file).keyObject
def getPrivateKey(self):
return defer.succeed(keys.Key.fromFile(private_key_file).keyObject)
class ClientConnection(connection.SSHConnection):
def serviceStarted(self):
self.openChannel(CatChannel(conn = self))
class CatChannel(channel.SSHChannel):
name = 'session'
def channelOpen(self, data):
d = self.conn.sendRequest(self, 'exec', common.NS('cat'), wantReply = 1)
d.addCallback(self._cbSendRequest)
self.catData = ''
def _cbSendRequest(self, ignored):
self.write('This data will be echoed back to us by "cat."\r\n')
self.conn.sendEOF(self)
self.loseConnection()
def dataReceived(self, data):
self.catData += data
def closed(self):
print 'We got this from "cat":', self.catData
def main():
hostname = "myhost"
factory = protocol.ClientFactory()
factory.protocol = ClientTransport
reactor.connectTCP(hostname, 22, factory)
log.startLogging(sys.stdout, setStdout=1)
reactor.run()
if __name__ == "__main__":
main()
そして、ここに完全なログがあります:
[-] Log opened.
[ClientTransport,client] kex alg, key alg: diffie-hellman-group-exchange-sha1 ssh-rsa
[ClientTransport,client] outgoing: aes256-ctr hmac-sha1 none
[ClientTransport,client] incoming: aes256-ctr hmac-sha1 none
[ClientTransport,client] REVERSE
[ClientTransport,client] NEW KEYS
[ClientTransport,client] Key algorythm: ssh-rsa
[ClientTransport,client] starting service ssh-userauth
[SSHService ssh-userauth on ClientTransport,client] can continue with: ['publickey']
[SSHService ssh-userauth on ClientTransport,client] trying to auth with publickey
[SSHService ssh-userauth on ClientTransport,client] Disconnecting with error, code 14
reason: no more authentication methods available
[ClientTransport,client] connection lost
[ClientTransport,client] Stopping factory <twisted.internet.protocol.ClientFactory instance at 0x13c2f908>
OpenSSH SSH クライアントと paramiko lib を使用してエラーなしでサーバーに接続できるため、問題は私のコードの何が問題なのかということです。