2

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?

8
  • @JNevill I meant passwd = input('Password:') but the problem is your password is visable while typing it. Can we change somehow getpass() to work like input line above? Mar 20 at 15:02
  • but in work there is a problem with connecting to SSH Well, what is the problem? What does the code actually do? Mar 20 at 15:05
  • @chepner Oh! Thanks for the clarification. I had completely misinterpreted how it worked :/ I will delete my comment.
    – JNevill
    Mar 20 at 15:14
  • @JohnGordon it connects you to the linux server Mar 20 at 15:35
  • I don't think I'm gonna be able to help but I think your question would benefit from adding details of what differs between your home environment and your work environment.
    – Savir
    Mar 20 at 16:55

1 Answer 1

0

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
2
  • 1
    Yes I know that as i wrote above, but I'm looking for some solution to keep the pass hiden - I know I can just write function to * the passwd but I would lov to keep it the same as the getpass did. Mar 20 at 15:37
  • You could do a trick to disables the terminal echo with termios while the user types the password, then restores the echo afterwards
    – Saxtheowl
    Mar 20 at 15:50

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.