Can't pass password to SSH by getpass

123 views Asked by At

I have code like under:

def acces_machine_connnect():
    print(namess.secnd_banner)
    login = input('Login: ')
    passwd = getpass.getpass('Password:')
    
    ssh_proxy = paramiko.SSHClient()
    ssh_proxy.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    ssh_proxy.connect(Acces_machine, username=login, password=passwd)
    return ssh_proxy

It works fine when I'am testing at my home, but in work there is a problem with connecting to SSH but after chaning passwd = getpass.getpass('Password:') to normal input it works completly fine. Any idea why this might happens? Or how can I change the code to make it works?

1

There are 1 answers

2
Saxtheowl On

You could try with input instead of getpass because getpass can bug depending on the terminal you are using

Here is how to do it:

import paramiko

def access_machine_connect():
    print(namess.secnd_banner)
    login = input('Login: ')
    print("Warning: Password input will be visible")
    passwd = input('Password: ')

    ssh_proxy = paramiko.SSHClient()
    ssh_proxy.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    ssh_proxy.connect(Acces_machine, username=login, password=passwd)
    return ssh_proxy