Python 3.3 on RHEL 6.
With the code below, if I get the password right the first time, it correctly prints 'authenticated', then returns me to my shell. If I get the password wrong 3 times it correctly prints 'Too many tries, sorry.', then returns me to my shell. But if I get the password wrong once or twice, then get it right, it prints 'authenticated', but then just hangs there and does not send me back to my shell. I have to press CTRL-C to break out of the script.
Any ideas?
import paramiko
import getpass
authenticated, tries = False, 1
while authenticated == False and tries <= 3:
try:
password = getpass.getpass('Password: ')
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(myhost, username=myusername, password=password)
authenticated = True
except paramiko.AuthenticationException:
authenticated = False
tries += 1
if authenticated == False:
print('Too many tries, sorry.')
else:
print('Authenticated')