How to login the super user(root) in remote host system using pexpect?

前端 未结 2 1135
挽巷
挽巷 2021-01-27 07:12

How to login the super user(root) in remote host system using pexpect?

user = root user
password = \'pass\'
child = pexpect.spawn(\'ssh %s@%s\'%(user,host,))


        
相关标签:
2条回答
  • 2021-01-27 07:57

    i will get answer

    child = pexpext.spawn('ssh root@host')
    
    0 讨论(0)
  • 2021-01-27 07:58

    You could also simply log in to a user on ssh like normal, then send commands to log into the root like you normally would in a terminal.

    #log into user account
    child = pexpect.spawn('ssh clientuser@localhost')
    child.expect('Password:')
    child.sendline('password')
    #then log into root account
    child.sendline('su')
    child.expect('Password:')
    child.sendline('sudopassword1234')
    

    This is just longer and more code, and probably only works on linux the way i wrote it. But you could use this if directly ssh to root doesn't work.

    0 讨论(0)
提交回复
热议问题