Python - Pxssh - Getting an password refused error when trying to login to a remote server

前端 未结 2 1571
鱼传尺愫
鱼传尺愫 2021-01-16 09:00

I\'m trying to use the pexpect module pxssh to log in into my one of my server. I get password refused. I think I know what it is the problem, but can\'t figure out how to f

2条回答
  •  [愿得一人]
    2021-01-16 09:36

    This error came for ssh is lock.so open the terminals and execute that command

    xxxx@toad:~$ rm .ssh/known_hosts
    

    remove the known_hosts

    another options is you login in windows means check command prompt. if you try to login in windows means use for pexpect

    child = pexpect.spawn('ssh tiger@172.16.0.190 -p 8888')
    child.logfile = open("/tmp/mylog", "w")
    print child.before
    child.expect('.*Are you sure you want to continue connecting (yes/no)?')
    child.sendline("yes")
    
    child.expect(".*assword:")
    child.sendline("tiger\r")
    child.expect('Press any key to continue...')
    child.send('\r')
    child.expect('C:\Users\.*>')
    child.sendline('dir')
    child.prompt('C:\Users\.*>')
    

    pxssh uses the shell prompt to synchronize output from the remote host.

    In order to make this more robust it sets the shell prompt to something more unique than just $ or #. This should work on most Borne/Bash or Csh style shells. Refer http://www.pythonforbeginners.com/code-snippets-source-code/ssh-connection-with-python/

提交回复
热议问题