当前位置: 首页>>代码示例>>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;未经允许,请勿转载。