from twisted.cred import portal, checkers from twisted.conch import manhole, manhole_ssh from twisted.conch.ssh import keys from twisted.python import filepath import hashlib import os def hash(username, netpass, localpass): return hashlib.sha1(netpass).hexdigest() def getManholeFactory(namespace, filename): def getManhole(_): return manhole.Manhole(namespace) realm = manhole_ssh.TerminalRealm() realm.chainedProtocolFactory.protocolFactory = getManhole p = portal.Portal(realm) p.registerChecker(checkers.FilePasswordDB(filename, hash = hash)) factory = manhole_ssh.ConchFactory(p) ssh_key = keys._getPersistentRSAKey(filepath.FilePath(os.path.expanduser('~/.fot.ssh')).child('id_rsa'), 2048) factory.publicKeys[b'ssh-rsa'] = ssh_key factory.privateKeys[b'ssh-rsa'] = ssh_key return factory if __name__ == '__main__': from twisted.internet import reactor factory = getManholeFactory({'x': 'foo'}, os.path.expanduser('~/.fot.users')) reactor.listenTCP(5022, factory) reactor.run()