import paramiko | |
# Define key file names | |
private_key_file = 'test_rsa.key' | |
public_key_file = 'test_rsa.key.pub' | |
# Generate RSA key pair | |
key = paramiko.RSAKey.generate(bits=2048) | |
# Save private key | |
with open(private_key_file, 'wb') as f: | |
key.write_private_key_file(private_key_file) | |
# Save public key | |
with open(public_key_file, 'wb') as f: | |
f.write(key.get_base64()) | |
print(f'RSA key pair generated and saved:') | |
print(f'Private key: {private_key_file}') | |
print(f'Public key: {public_key_file}') | |