Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Two way authentication / keyboard_interactive method #345

Unanswered
mimoshe asked this question in Q&A
Discussion options

Hello team,
I need to connect to Linux server that uses two way authentication per user
for example in putty when I ssh it will ask for username, then prompt for PIN once this provided, it will prompt for a password, once that provided the server will accept the handshake and create the connection.
Any idea how accomplish this with ssh2-Python?

so far my code is simple

`import socket
from ssh2.session import Session
from getpass import getpass

host = input("Enter Hostname :")
user = input("Enter Username :")
password = getpass("Enter Password :")

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((host, 22))
session = Session()

session.handshake(sock)
session.userauth_keyboardinteractive(user, password)

channel = session.open_session()
channel.execute('ls -l')
size, data = channel.read()
while size > 0:
print(data.decode())
size, data = channel.read()

channel.close()
print("Exit status: {0}".format(channel.get_exit_status()))`

currently the [session.userauth_keyboardinteractive(user, password)] line is getting ssh2.exceptions.AuthenticationError

Any help is appreciated

You must be logged in to vote

Replies: 1 comment

Comment options

Try with the standard username/password authentication feature and see if that works for you.

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /