Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #95454 > unrolled thread

execute commands as su on remote server

Started byharirammanohar159@gmail.com
First post2015-08-17 19:57 -0700
Last post2015-10-01 00:10 -0700
Articles 10 — 4 participants

Back to article view | Back to comp.lang.python


Contents

  execute commands as su on remote server harirammanohar159@gmail.com - 2015-08-17 19:57 -0700
    Re: execute commands as su on remote server Chris Angelico <rosuav@gmail.com> - 2015-08-18 13:06 +1000
    Re: execute commands as su on remote server harirammanohar159@gmail.com - 2015-08-18 23:58 -0700
    Re: execute commands as su on remote server harirammanohar159@gmail.com - 2015-08-19 00:02 -0700
      Re: execute commands as su on remote server Laura Creighton <lac@openend.se> - 2015-08-19 10:44 +0200
      Re: execute commands as su on remote server Laura Creighton <lac@openend.se> - 2015-08-19 10:51 +0200
    Re: execute commands as su on remote server harirammanohar159@gmail.com - 2015-09-01 05:16 -0700
      Re: execute commands as su on remote server Laura Creighton <lac@openend.se> - 2015-09-01 15:25 +0200
    Re: execute commands as su on remote server Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2015-09-02 09:05 +0200
    Re: execute commands as su on remote server harirammanohar159@gmail.com - 2015-10-01 00:10 -0700

#95454 — execute commands as su on remote server

Fromharirammanohar159@gmail.com
Date2015-08-17 19:57 -0700
Subjectexecute commands as su on remote server
Message-ID<a6b3da0b-d9be-4241-8577-85aafca72440@googlegroups.com>
execute commands as su on remote server

Postby hariram » Mon Aug 17, 2015 4:02 am
Needed:
I need to execute commands after doing su to other user on remote server(not sudo which doesn't require password) how i can achieve this using python?
I googled and came to know that its not possible, so just for confirmation asking again, is it possible ?

Already Tried:
Tried paramiko that's too not working.

[toc] | [next] | [standalone]


#95455

FromChris Angelico <rosuav@gmail.com>
Date2015-08-18 13:06 +1000
Message-ID<mailman.70.1439867208.4764.python-list@python.org>
In reply to#95454
On Tue, Aug 18, 2015 at 12:57 PM,  <harirammanohar159@gmail.com> wrote:
> I need to execute commands after doing su to other user on remote server(not sudo which doesn't require password) how i can achieve this using python?
> I googled and came to know that its not possible, so just for confirmation asking again, is it possible ?

Ultimately, this isn't a Python question, it's a systems
administration one. You want a way to execute commands as a specific
user, triggering them remotely. There are basically two ways you can
do this: either you provide some form of credentials (this is what
sudo does), or you elevate the entire management process. The latter
option is far FAR easier (running it as root if you might need to go
to any different user, or as that specific user if you'll only ever
use one), but then you have to ensure, in some way, that your Python
program can't be compromised.

Python has nothing to do with any of this. If you want to manage
elevation using sudo, Python can invoke sudo in a subprocess. If you
want to elevate the Python process and then simply invoke something
directly, Python won't even be aware of it.

ChrisA

[toc] | [prev] | [next] | [standalone]


#95477

Fromharirammanohar159@gmail.com
Date2015-08-18 23:58 -0700
Message-ID<0eedd27d-e806-468f-9e1e-6e9cf49eb3c5@googlegroups.com>
In reply to#95454
On Tuesday, 18 August 2015 08:27:33 UTC+5:30, hariramm...@gmail.com  wrote:
> execute commands as su on remote server
> 
> Postby hariram » Mon Aug 17, 2015 4:02 am
> Needed:
> I need to execute commands after doing su to other user on remote server(not sudo which doesn't require password) how i can achieve this using python?
> I googled and came to know that its not possible, so just for confirmation asking again, is it possible ?
> 
> Already Tried:
> Tried paramiko that's too not working.

Hey Chris,
Thanks for that, requirement is not to use sudo, we have to use only su.
anyway i have tried with subprocess too with su which is not working as it needs tty...even paramiko also SSHClient...

[toc] | [prev] | [next] | [standalone]


#95478

Fromharirammanohar159@gmail.com
Date2015-08-19 00:02 -0700
Message-ID<fa8fe84e-23fa-4616-b4a9-03dda6dc4396@googlegroups.com>
In reply to#95454
On Tuesday, 18 August 2015 08:27:33 UTC+5:30, hariramm...@gmail.com  wrote:
> execute commands as su on remote server
> 
> Postby hariram » Mon Aug 17, 2015 4:02 am
> Needed:
> I need to execute commands after doing su to other user on remote server(not sudo which doesn't require password) how i can achieve this using python?
> I googled and came to know that its not possible, so just for confirmation asking again, is it possible ?
> 
> Already Tried:
> Tried paramiko that's too not working.

Hey Julio,

i have seen that in forums speaking about fabfile... but i believe that it also supports only sudo not su...sudo rights we dont have in our env...
even fabfile implementation is up to python 2.7 only and we are using python 3.4

Tried creating channel and invoking shell and spawning it delay, that too didnt worked, just checking that any possible way is there to control the tty..

[toc] | [prev] | [next] | [standalone]


#95480

FromLaura Creighton <lac@openend.se>
Date2015-08-19 10:44 +0200
Message-ID<mailman.5.1439973900.28100.python-list@python.org>
In reply to#95478
I haven't tried this but fabric looks encouraging:

From http://docs.fabfile.org/en/latest/api/core/operations.html#fabric.operations.run

 fabric.operations.run(*args, **kwargs)

    Run a shell command on a remote host.

    ...

    Any text entered in your local terminal will be forwarded to the
    remote program as it runs, thus allowing you to interact with
    password or other prompts naturally

    ...

    You may pass pty=False to forego creation of a pseudo-terminal on
    the remote end in case the presence of one causes problems for the
    command in question.

Laura

[toc] | [prev] | [next] | [standalone]


#95481

FromLaura Creighton <lac@openend.se>
Date2015-08-19 10:51 +0200
Message-ID<mailman.6.1439974325.28100.python-list@python.org>
In reply to#95478
In a message of Wed, 19 Aug 2015 10:44:53 +0200, Laura Creighton writes:
>I haven't tried this but fabric looks encouraging:
>
>>From http://docs.fabfile.org/en/latest/api/core/operations.html#fabric.operations.run
>
> fabric.operations.run(*args, **kwargs)
>
>    Run a shell command on a remote host.
>
>    ...
>
>    Any text entered in your local terminal will be forwarded to the
>    remote program as it runs, thus allowing you to interact with
>    password or other prompts naturally
>
>    ...
>
>    You may pass pty=False to forego creation of a pseudo-terminal on
>    the remote end in case the presence of one causes problems for the
>    command in question.
>
>Laura
>-- 
>https://mail.python.org/mailman/listinfo/python-list

And now that I started looking, I found this:
http://stackoverflow.com/questions/12641514/switch-to-different-user-using-fabric

so, somebody got it to work ...

Laura

[toc] | [prev] | [next] | [standalone]


#95829

Fromharirammanohar159@gmail.com
Date2015-09-01 05:16 -0700
Message-ID<23e7c934-e8f1-4c8f-a44a-fcbb390381b4@googlegroups.com>
In reply to#95454
On Tuesday, 18 August 2015 08:27:33 UTC+5:30, hariramm...@gmail.com  wrote:
> execute commands as su on remote server
> 
> Postby hariram » Mon Aug 17, 2015 4:02 am
> Needed:
> I need to execute commands after doing su to other user on remote server(not sudo which doesn't require password) how i can achieve this using python?
> I googled and came to know that its not possible, so just for confirmation asking again, is it possible ?
> 
> Already Tried:
> Tried paramiko that's too not working.

Hey Laura,

fabric doesnt work for me as fabric works with only up to python 2.7 and we are using python 3.3, so we may miss major functionalists if we use 2.7 again in the entire project...

[toc] | [prev] | [next] | [standalone]


#95830

FromLaura Creighton <lac@openend.se>
Date2015-09-01 15:25 +0200
Message-ID<mailman.44.1441113955.23514.python-list@python.org>
In reply to#95829
In a message of Tue, 01 Sep 2015 05:16:48 -0700, harirammanohar159@gmail.com wr
ites:
>On Tuesday, 18 August 2015 08:27:33 UTC+5:30, hariramm...@gmail.com  wrote:
>> execute commands as su on remote server
>> 
>> Postby hariram » Mon Aug 17, 2015 4:02 am
>> Needed:
>> I need to execute commands after doing su to other user on remote server(not sudo which doesn't require password) how i can achieve this using python?
>> I googled and came to know that its not possible, so just for confirmation asking again, is it possible ?
>> 
>> Already Tried:
>> Tried paramiko that's too not working.
>
>Hey Laura,
>
>fabric doesnt work for me as fabric works with only up to python 2.7 and we are using python 3.3, so we may miss major functionalists if we use 2.7 again in the entire project...
>-- 
>https://mail.python.org/mailman/listinfo/python-list

Over here is a Python 3 fork of fabric.
https://github.com/pashinin/fabric

It is not complete -- i.e. he disabled some tests so some things aren't
working.  But most of it is reported to work, so maybe it will work
well enough for you to use until fabric gets ported for real.

Laura

[toc] | [prev] | [next] | [standalone]


#95856

FromAntoon Pardon <antoon.pardon@rece.vub.ac.be>
Date2015-09-02 09:05 +0200
Message-ID<mailman.7.1441177606.8327.python-list@python.org>
In reply to#95454
Op 18-08-15 om 04:57 schreef harirammanohar159@gmail.com:
> execute commands as su on remote server
>
> Postby hariram » Mon Aug 17, 2015 4:02 am
> Needed:
> I need to execute commands after doing su to other user on remote server(not sudo which doesn't require password) how i can achieve this using python?
> I googled and came to know that its not possible, so just for confirmation asking again, is it possible ?
>
> Already Tried:
> Tried paramiko that's too not working.

What about pexpect: https://pypi.python.org/pypi/pexpect/

It's been a long time since I used it, but it was for something
similar.

-- 
Antoon Pardon

[toc] | [prev] | [next] | [standalone]


#97266

Fromharirammanohar159@gmail.com
Date2015-10-01 00:10 -0700
Message-ID<71746612-9695-4003-8a69-fcbdb1a52789@googlegroups.com>
In reply to#95454
On Tuesday, 18 August 2015 08:27:33 UTC+5:30, hariramm...@gmail.com  wrote:
> execute commands as su on remote server
> 
> Postby hariram » Mon Aug 17, 2015 4:02 am
> Needed:
> I need to execute commands after doing su to other user on remote server(not sudo which doesn't require password) how i can achieve this using python?
> I googled and came to know that its not possible, so just for confirmation asking again, is it possible ?
> 
> Already Tried:
> Tried paramiko that's too not working.

Thanks laura, i am able to acheive it using pxssh...

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web