Reputation: 15
I new in python, I am try to connect RHEL vm
by key authentication
.I have two RHEL6.5 vm1,vm2
and Python 2.6.6
on both.
First I generate keys on vm1 and copy to vm2 as using below cmd.
On vm1 execute below cmd:
1) ssh-keygen -t rsa
2) After key generation
3) ssh-copy-id -i .ssh/id_rsa.pub root@vm2
After that I am able to login that vm2 from vm1
ssh -i /root/.ssh/id_rsa root@vm2
manually this is working fine but i am doing it programmatically by using python, below is my code: run from vm1
SSHKey.py
import paramiko
sshcon = paramiko.SSHClient()
sshcon.set_missing_host_key_policy(paramiko.AutoAddPolicy())
connection = sshcon.connect('vm2', 'root','/root/.ssh/id_rsa')
print "-----------------"
print connection
**OutPut:**
Traceback (most recent call last):
File "SSHKey.py", line 5, in <module>
connection = sshcon.connect('vm2', 'root')
File "/usr/lib/python2.6/site-packages/paramiko/client.py", line 277, in connect
socket.getaddrinfo(hostname, port):
socket.gaierror: [Errno -8] Servname not supported for ai_socktype
Upvotes: 0
Views: 360
Reputation: 666
I think RHEL6.5 vm1 not able to communicate with RHEL6.5 vm2.Python version looks good you need to install paramiko on RHEL6.5 vm2.Run below cmd.
1) yum list python-paramiko --showduplicates This will give you available package 2) yum install python-paramiko This will install paramiko on your rhel vm.
Upvotes: 2