當前位置: 首頁>>代碼示例>>Python>>正文


Python paramiko.RSAKey方法代碼示例

本文整理匯總了Python中paramiko.RSAKey方法的典型用法代碼示例。如果您正苦於以下問題:Python paramiko.RSAKey方法的具體用法?Python paramiko.RSAKey怎麽用?Python paramiko.RSAKey使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在paramiko的用法示例。


在下文中一共展示了paramiko.RSAKey方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: validate_key

# 需要導入模塊: import paramiko [as 別名]
# 或者: from paramiko import RSAKey [as 別名]
def validate_key(key_path):
    """ Validate a key

        :param key_path: path to a key to use for authentication
        :type key_path: str

        :return: key object used for authentication
        :rtype: paramiko.RSAKey
    """

    key_path = os.path.expanduser(key_path)

    if not os.path.isfile(key_path):
        return False

    return paramiko.RSAKey.from_private_key_file(key_path) 
開發者ID:dcos,項目名稱:shakedown,代碼行數:18,代碼來源:helpers.py

示例2: get_authorized_keys

# 需要導入模塊: import paramiko [as 別名]
# 或者: from paramiko import RSAKey [as 別名]
def get_authorized_keys(path):
    keys = []
    with open(path) as fp:
        for line in fp:
            flds = line.split(' ')
            if len(flds) < 2: continue
            if flds[0] == 'ssh-rsa':
                f = paramiko.RSAKey
            elif flds[0] == 'ssh-dss':
                f = paramiko.DSSKey
            elif flds[0].startswith('ecdsa-'):
                f = paramiko.ECDSAKey
            else:
                continue
            data = decodebytes(flds[1].encode('ascii'))
            keys.append(f(data=data))
    return keys

# run_server 
開發者ID:euske,項目名稱:pyrexecd,代碼行數:21,代碼來源:__init__.py

示例3: get_pkey_obj

# 需要導入模塊: import paramiko [as 別名]
# 或者: from paramiko import RSAKey [as 別名]
def get_pkey_obj(cls, privatekey, password, filename):
        bpass = to_bytes(password) if password else None

        pkey = cls.get_specific_pkey(paramiko.RSAKey, privatekey, bpass)\
            or cls.get_specific_pkey(paramiko.DSSKey, privatekey, bpass)\
            or cls.get_specific_pkey(paramiko.ECDSAKey, privatekey, bpass)\
            or cls.get_specific_pkey(paramiko.Ed25519Key, privatekey, bpass)

        if not pkey:
            if not password:
                error = 'Invalid private key: {}'.format(filename)
            else:
                error = (
                    'Wrong password {!r} for decrypting the private key.'
                ) .format(password)
            raise InvalidValueError(error)

        return pkey 
開發者ID:guohongze,項目名稱:adminset,代碼行數:20,代碼來源:handler.py

示例4: ssh_key_gen

# 需要導入模塊: import paramiko [as 別名]
# 或者: from paramiko import RSAKey [as 別名]
def ssh_key_gen(length=2048, type='rsa', password=None, username='jumpserver', hostname=None):
    """Generate user ssh private and public key

    Use paramiko RSAKey generate it.
    :return private key str and public key str
    """

    if hostname is None:
        hostname = os.uname()[1]

    f = StringIO()
    try:
        if type == 'rsa':
            private_key_obj = paramiko.RSAKey.generate(length)
        elif type == 'dsa':
            private_key_obj = paramiko.DSSKey.generate(length)
        else:
            raise IOError('SSH private key must be `rsa` or `dsa`')
        private_key_obj.write_private_key(f, password=password)
        private_key = f.getvalue()
        public_key = ssh_pubkey_gen(private_key_obj, username=username, hostname=hostname)
        return private_key, public_key
    except IOError:
        raise IOError('These is error when generate ssh key.') 
開發者ID:getway,項目名稱:diting,代碼行數:26,代碼來源:utils.py

示例5: _check_deserialize_key

# 需要導入模塊: import paramiko [as 別名]
# 或者: from paramiko import RSAKey [as 別名]
def _check_deserialize_key(key):
    res = None
    if isinstance(key, paramiko.RSAKey):
        LOG.trace("Key is already in the proper format.")
        res = key
    elif type(key) is str:
        LOG.trace("Deserializing PEM-encoded private key.")
        res = utils.deserialize_key(
            key, CONF.serialization.temp_keypair_password)
    else:
        raise exception.CoriolisException(
            "Private key must be either a PEM-encoded string or "
            "a paramiko.RSAKey instance. Got type '%s'." % (
                type(key)))

    return res 
開發者ID:cloudbase,項目名稱:coriolis,代碼行數:18,代碼來源:backup_writers.py

示例6: test_7_banner_timeout

# 需要導入模塊: import paramiko [as 別名]
# 或者: from paramiko import RSAKey [as 別名]
def test_7_banner_timeout(self):
        """
        verify that the SSHClient has a configurable banner timeout.
        """
        # Start the thread with a 1 second wait.
        threading.Thread(target=self._run, kwargs={'delay': 1}).start()
        host_key = paramiko.RSAKey.from_private_key_file(test_path('test_rsa.key'))
        public_host_key = paramiko.RSAKey(data=host_key.asbytes())

        self.tc = paramiko.SSHClient()
        self.tc.get_host_keys().add('[%s]:%d' % (self.addr, self.port), 'ssh-rsa', public_host_key)
        # Connect with a half second banner timeout.
        kwargs = dict(self.connect_kwargs, banner_timeout=0.5)
        self.assertRaises(
            paramiko.SSHException,
            self.tc.connect,
            **kwargs
        ) 
開發者ID:hpe-storage,項目名稱:python-hpedockerplugin,代碼行數:20,代碼來源:test_client.py

示例7: connect

# 需要導入模塊: import paramiko [as 別名]
# 或者: from paramiko import RSAKey [as 別名]
def connect(self, host, user, password=None, ssh_key=None, port=22, timeout=30,
                term='xterm', pty_width=80, pty_height=24):
        try:
            ssh_client = paramiko.SSHClient()
            ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())

            if ssh_key:
                key = get_key_obj(paramiko.RSAKey, pkey_obj=ssh_key, password=password) or \
                      get_key_obj(paramiko.DSSKey, pkey_obj=ssh_key, password=password) or \
                      get_key_obj(paramiko.ECDSAKey, pkey_obj=ssh_key, password=password) or \
                      get_key_obj(paramiko.Ed25519Key, pkey_obj=ssh_key, password=password)

                ssh_client.connect(username=user, hostname=host, port=port, pkey=key, timeout=timeout)
            else:
                ssh_client.connect(username=user, password=password, hostname=host, port=port, timeout=timeout)

            transport = ssh_client.get_transport()
            self.channel = transport.open_session()
            self.channel.get_pty(term=term, width=pty_width, height=pty_height)
            self.channel.invoke_shell()

            for i in range(2):
                recv = self.channel.recv(1024).decode('utf-8')
                self.message['status'] = 0
                self.message['message'] = recv
                message = json.dumps(self.message)
                self.websocker.send(message)
        except socket.timeout:
            self.message['status'] = 1
            self.message['message'] = 'ssh 連接超時'
            message = json.dumps(self.message)
            self.websocker.send(message)
            self.close()
        except:
            self.close() 
開發者ID:huyuan1999,項目名稱:django-webssh,代碼行數:37,代碼來源:ssh.py

示例8: get_pkey

# 需要導入模塊: import paramiko [as 別名]
# 或者: from paramiko import RSAKey [as 別名]
def get_pkey(self, privatekey, password):
        password = password.encode('utf-8') if password else None

        pkey = self.get_specific_pkey(paramiko.RSAKey, privatekey, password)\
            or self.get_specific_pkey(paramiko.DSSKey, privatekey, password)\
            or self.get_specific_pkey(paramiko.ECDSAKey, privatekey, password)\
            or self.get_specific_pkey(paramiko.Ed25519Key, privatekey,
                                      password)
        if not pkey:
            raise ValueError('Not a valid private key file or '
                             'wrong password for decrypting the private key.')
        return pkey 
開發者ID:hequan2017,項目名稱:chain,代碼行數:14,代碼來源:main.py

示例9: test_get_pkey_obj_with_plain_rsa_key

# 需要導入模塊: import paramiko [as 別名]
# 或者: from paramiko import RSAKey [as 別名]
def test_get_pkey_obj_with_plain_rsa_key(self):
        pk = self.get_pk_obj('test_rsa.key')
        self.assertIsInstance(pk.get_pkey_obj(), paramiko.RSAKey) 
開發者ID:huashengdun,項目名稱:webssh,代碼行數:5,代碼來源:test_handler.py

示例10: test_get_pkey_obj_with_encrypted_rsa_key

# 需要導入模塊: import paramiko [as 別名]
# 或者: from paramiko import RSAKey [as 別名]
def test_get_pkey_obj_with_encrypted_rsa_key(self):
        fname = 'test_rsa_password.key'
        password = 'television'
        self._test_with_encrypted_key(fname, password, paramiko.RSAKey) 
開發者ID:huashengdun,項目名稱:webssh,代碼行數:6,代碼來源:test_handler.py

示例11: test_get_pkey_obj_with_encrypted_new_rsa_key

# 需要導入模塊: import paramiko [as 別名]
# 或者: from paramiko import RSAKey [as 別名]
def test_get_pkey_obj_with_encrypted_new_rsa_key(self):
        fname = 'test_new_rsa_password.key'
        password = '123456'
        self._test_with_encrypted_key(fname, password, paramiko.RSAKey) 
開發者ID:huashengdun,項目名稱:webssh,代碼行數:6,代碼來源:test_handler.py

示例12: __init__

# 需要導入模塊: import paramiko [as 別名]
# 或者: from paramiko import RSAKey [as 別名]
def __init__(self, server, client_conn):
        self.server = server
        self.thread = None
        self.command_queues = {}
        client, _ = client_conn
        self.transport = t = paramiko.Transport(client)
        t.add_server_key(paramiko.RSAKey(filename=SERVER_KEY_PATH))
        t.set_subsystem_handler("sftp", sftp.SFTPServer) 
開發者ID:carletes,項目名稱:mock-ssh-server,代碼行數:10,代碼來源:server.py

示例13: add_user

# 需要導入模塊: import paramiko [as 別名]
# 或者: from paramiko import RSAKey [as 別名]
def add_user(self, uid, private_key_path, keytype="ssh-rsa"):
        if keytype == "ssh-rsa":
            key = paramiko.RSAKey.from_private_key_file(private_key_path)
        elif keytype == "ssh-dss":
            key = paramiko.DSSKey.from_private_key_file(private_key_path)
        elif keytype in paramiko.ECDSAKey.supported_key_format_identifiers():
            key = paramiko.ECDSAKey.from_private_key_file(private_key_path)
        elif keytype == "ssh-ed25519":
            key = paramiko.Ed25519Key.from_private_key_file(private_key_path)
        else:
            raise Exception("Unable to handle key of type {}".format(keytype))

        self._users[uid] = (private_key_path, key) 
開發者ID:carletes,項目名稱:mock-ssh-server,代碼行數:15,代碼來源:server.py

示例14: client

# 需要導入模塊: import paramiko [as 別名]
# 或者: from paramiko import RSAKey [as 別名]
def client(self, uid):
        private_key_path, _ = self._users[uid]
        c = paramiko.SSHClient()
        host_keys = c.get_host_keys()
        key = paramiko.RSAKey.from_private_key_file(SERVER_KEY_PATH)
        host_keys.add(self.host, "ssh-rsa", key)
        host_keys.add("[%s]:%d" % (self.host, self.port), "ssh-rsa", key)
        c.set_missing_host_key_policy(paramiko.RejectPolicy())
        c.connect(hostname=self.host,
                  port=self.port,
                  username=uid,
                  key_filename=private_key_path,
                  allow_agent=False,
                  look_for_keys=False)
        return c 
開發者ID:carletes,項目名稱:mock-ssh-server,代碼行數:17,代碼來源:server.py

示例15: load_keyfile

# 需要導入模塊: import paramiko [as 別名]
# 或者: from paramiko import RSAKey [as 別名]
def load_keyfile(keyfile):
  for cls in (paramiko.RSAKey, paramiko.DSSKey, paramiko.ECDSAKey):
    try:
      return cls.from_private_key_file(keyfile)
    except paramiko.SSHException:
      pass
  else:
    raise 
開發者ID:lanjelot,項目名稱:patator,代碼行數:10,代碼來源:patator.py


注:本文中的paramiko.RSAKey方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。