def import_ssh_key(private_key_file, passphrase=None):
"""
Import contents from RSA private key file
param private_key_file: path to private key file
param passphrase: passphrase for the private key, by default
None
return: contents from private key file
"""
key_file_contents = None
private_key_file = os.path.abspath(private_key_file)
try:
with open(private_key_file, 'r') as key_file:
key_file_contents = key_file.readlines()
return RSA.importKey(key_file_contents, passphrase=passphrase)
except IOError as ie:
raise exception.PrivateKeyNotFound(private_key_file)
except Exception as e:
raise exception.ImportKeyError(private_key_file)
评论列表
文章目录