I am generating private key from paramiko and tried connecting to my another machine using below code. I have saved key generated in .pub file. I have copied the same key in '~/.ssh/authorised_keys' file in my linux machine. I get error AuthenticationException: Authentication failed when I tried to connect.
import paramiko
key = paramiko.RSAKey.generate(1024)
fp = open('path\rsa_python.pub', 'w')
key.write_private_key(fp)
fp.close()
## Copied key to linux machine.
k = paramiko.RSAKey.from_private_key_file(r'path\rsa_python.pub')
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('linux_machine', username='***', pkey=k)
I am not getting where I am going wrong. Please help me with some code.