0

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,))
Reegan Miranda
  • 2,879
  • 6
  • 43
  • 55

2 Answers2

1

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.

PyFire
  • 101
  • 1
  • 8
0

i will get answer

child = pexpext.spawn('ssh root@host')
Reegan Miranda
  • 2,879
  • 6
  • 43
  • 55