#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    4
    Rep Power
    0

    How to do "sudo -s" and access root terminal.


    Hi,

    how to do "sudo -s" and access root terminal with paramiko module

    or
    please suggest me any other module.

    Thanks,
    Pragva.
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    14
    Rep Power
    0
    Is there a specific command you want to run with sudo? Can you run your script with sudo or as root to avoid handling it with the script?

    You can execute arbitrary shell commands with the subprocess module.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    4
    Rep Power
    0
    Thanks for the reply.

    We are using power broker for server root auth it something like below.
    I 'm able to login f16 as normal user to do some tasks as root, i have to run "pbrun vmgrp -u root -p" and access the root terminal
    It's something like below and want to do with python as of now i'm using paramiko somebody suggested me to do with getpty() still issues.

    [pragva@f17 ~]$ ssh f16

    Password:
    Last login: Tue Feb 19 11:19:36 2013 from localhost

    [pragva@f16 ~]$ pbrun vmgrp -u root -p
    Password:

    su from pragva to root at Wed Feb 20 05:42:19 IST 2013
    [root@f16 ~]#
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    4
    Rep Power
    0
    Is it possible to achieve with fabric!!!!!
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    4
    Rep Power
    0
    I got it with paramiko.


    from paramiko import SSHClient, SSHConfig
    ssh_client = SSHClient()
    ssh_client.load_system_host_keys()
    ssh_client.connect('localhost', username='user1',password='pass123')
    chan = ssh_client.invoke_shell()
    chan.send("sudo -s\n")
    buff = ' '
    while not buff.endswith("password: "):
    ...resp = chan.recv(9999)
    ...buff += resp
    print buff
    print "before pwd entered."
    chan.send("pass123\n")
    print "pwd entered"


    Thanks for the replies

IMN logo majestic logo threadwatch logo seochat tools logo