Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import paramiko
- import os
- def copy_ssh_key(user, host, port, key_file):
- key = paramiko.RSAKey(filename=key_file)
- client = paramiko.SSHClient()
- client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
- try:
- client.connect(hostname=host, port=port, username=user, pkey=key)
- ssh_command = f"echo {key.get_base64()} >> ~/.ssh/authorized_keys"
- stdin, stdout, stderr = client.exec_command(ssh_command)
- print(f"Key copied to {host} successfully.")
- except Exception as e:
- print(f"Failed to copy key to {host}: {str(e)}")
- finally:
- client.close()
- def main():
- pass
- if __name__ == "__main__":
- main()
Add Comment
Please, Sign In to add comment