1
import paramiko

host = "172.21.14.48"
port = 22
username = "user"
password = "xxx*9841"
command = "ls"
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(host, port, username, password )
stdin, stdout, stderr = ssh.exec_command(command)
lines = stdout.readlines()
print(lines)

This code works SSH successful. But I need to ssh to [email protected] with same username and password.

Using username "cp".
Keyboard-interactive authentication prompts from server:
Actual Username:
Actual Password:

I tried below code but getting error.

host = "[email protected]"

Error message as:

File "C:\Program Files\Python38\lib\socket.py", line 918, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags): socket.gaierror: [Errno 11003] getaddrinfo failed

However with PuTTY I can ssh to [email protected]. Any suggestion..?

0

1 Answer 1

1

The cp in the ssh [email protected] is a username, so it goes to the username argument of SSHClient.connect:

username = "cp"
# ...
ssh = paramiko.SSHClient()
ssh.connect(host, port, username, password)

Your server prompts for another set of credentials using keyboard interactive authentication.
For that see: Password authentication in Python Paramiko fails, but same credentials work in SSH/SFTP client
You have to adjust the code to answer both the second username and password prompts. The fields parameter of the handler will have two entries and the handler has to return a two answers in its result.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.