Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

paramiko Error Servname not supported for ai_socktype

Tags:

paramiko

I am unable to connect to other server through paramiko:

import paramiko
import sys
import os

hostname = 'server1'
port = 22
username = 'root'
password = 'password'`enter code here`
def deploy_key(key, hostname, username, password):
    client = paramiko.SSHClient()
    client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    client.connect(hostname, username, password)
    client.exec_command('mkdir -p ~/.ssh/')
    client.exec_command('echo "%s" > ~/.ssh/authorized_keys' % key)
    client.exec_command('chmod 644 ~/.ssh/authorized_keys')
    client.exec_command('chmod 700 ~/.ssh/')

key = open(os.path.expanduser('~/.ssh/id_rsa.pub')).read()
deploy_key(key, hostname, username, password)

Here was the output:

socket.AF_UNSPEC, socket.SOCK_STREAM):
socket.gaierror: [Errno -8] Servname not supported for ai_socktype
like image 917
Rohit_chd Avatar asked Mar 07 '14 13:03

Rohit_chd


1 Answers

The problem is with the call to client.connect(). It expects port to be second parameter and to be an integer, whereas you are giving username (string) as second parameter. Try replacing that with below line.

client.connect(hostname, username=username, password=password)

That should work.

like image 158
Sindhura Bandi Avatar answered Jan 03 '23 21:01

Sindhura Bandi