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?

Saxtheowl
  • 4,136
  • 5
  • 23
  • 32
  • @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? – Mateusz Plsz Mar 20 '23 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**? – John Gordon Mar 20 '23 at 15:05
  • @chepner Oh! Thanks for the clarification. I had completely misinterpreted how it worked :/ I will delete my comment. – JNevill Mar 20 '23 at 15:14
  • @JohnGordon it connects you to the linux server – Mateusz Plsz Mar 20 '23 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 '23 at 16:55
  • I wasn't asking what the code is **supposed** to do. You said there was a problem, so I was asking what the actual problem is. Do you get an error message? – John Gordon Mar 20 '23 at 17:08
  • @JohnGordon as I said it do not pass the password to the ssh it pass empty so I get creditential error paramiko.ssh_exception.AuthenticationException: Authentication failed. – Mateusz Plsz Mar 20 '23 at 17:55
  • It seems odd that `getpass()` would return a blank string. Are you sure it's blank? If you run a small python script that just calls `getpass()` and prints the result, what output do you see? – John Gordon Mar 20 '23 at 19:34

1 Answers1

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
Saxtheowl
  • 4,136
  • 5
  • 23
  • 32
  • 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. – Mateusz Plsz Mar 20 '23 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 '23 at 15:50