Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > supplying password to subprocess.call('rsync ...'), os.system('rsync ...')

Reply
Thread Tools

supplying password to subprocess.call('rsync ...'), os.system('rsync ...')

 
 
timw.google
Guest
Posts: n/a
 
      10-05-2007
Hi

I want to write a python script that runs rsync on a given directory
and host. I build the command line string, but when I try to run
subprocess.call(cmd), or p=subprocess.Popen(cmd, shell=True),or
os.system(cmd), I get prompted for my login password. I expected this,
but when I try to give my password, it's echoed back to the terminal
and the special characters in the password is (I think) getting
interpreted by the shell (zsh)

I can't ssh w/o supplying a password. That's the way the security is
set up here.

How do I use python to do this, or do I just have to write a zsh
script?

Thanks.

 
Reply With Quote
 
 
 
 
timw.google
Guest
Posts: n/a
 
      10-05-2007
On Oct 5, 10:33 am, "timw.google" <(E-Mail Removed)> wrote:
> Hi
>
> I want to write a python script that runs rsync on a given directory
> and host. I build the command line string, but when I try to run
> subprocess.call(cmd), or p=subprocess.Popen(cmd, shell=True),or
> os.system(cmd), I get prompted for my login password. I expected this,
> but when I try to give my password, it's echoed back to the terminal
> and the special characters in the password is (I think) getting
> interpreted by the shell (zsh)
>
> I can't ssh w/o supplying a password. That's the way the security is
> set up here.
>
> How do I use python to do this, or do I just have to write a zsh
> script?
>
> Thanks.


I wrote a zsh script to do what I wanted, but I'd still like to know
how to do it in Python.

 
Reply With Quote
 
 
 
 
Stargaming
Guest
Posts: n/a
 
      10-05-2007
On Fri, 05 Oct 2007 08:37:05 -0700, timw.google wrote:

> On Oct 5, 10:33 am, "timw.google" <(E-Mail Removed)> wrote:
>> Hi
>>
>> I want to write a python script that runs rsync on a given directory
>> and host. I build the command line string, but when I try to run
>> subprocess.call(cmd), or p=subprocess.Popen(cmd, shell=True),or
>> os.system(cmd), I get prompted for my login password. I expected this,
>> but when I try to give my password, it's echoed back to the terminal
>> and the special characters in the password is (I think) getting
>> interpreted by the shell (zsh)
>>
>> I can't ssh w/o supplying a password. That's the way the security is
>> set up here.
>>
>> How do I use python to do this, or do I just have to write a zsh
>> script?
>>
>> Thanks.

>
> I wrote a zsh script to do what I wanted, but I'd still like to know how
> to do it in Python.


`subprocess.Popen` has a keyword argument called `stdin` -- what takes
the password, I guess. Assigning `subprocess.PIPE` to it and using
`Popen.communicate` should do the trick.

Check the documentation at http://docs.python.org/lib/module-
subprocess.html for details.

Cheers,
Stargaming
 
Reply With Quote
 
Lawrence D'Oliveiro
Guest
Posts: n/a
 
      10-06-2007
In message <(E-Mail Removed). com>,
timw.google wrote:

> I want to write a python script that runs rsync on a given directory
> and host. I build the command line string, but when I try to run
> subprocess.call(cmd), or p=subprocess.Popen(cmd, shell=True),or
> os.system(cmd), I get prompted for my login password.


Why not set up a public/private SSH key pair between the accounts on the two
machines? Then you can get in without a password.

 
Reply With Quote
 
David
Guest
Posts: n/a
 
      10-07-2007
On 10/5/07, timw.google <(E-Mail Removed)> wrote:
> Hi
>
> I want to write a python script that runs rsync on a given directory
> and host. I build the command line string, but when I try to run
> subprocess.call(cmd), or p=subprocess.Popen(cmd, shell=True),or
> os.system(cmd), I get prompted for my login password. I expected this,
> but when I try to give my password, it's echoed back to the terminal
> and the special characters in the password is (I think) getting
> interpreted by the shell (zsh)
>
> I can't ssh w/o supplying a password. That's the way the security is
> set up here.
>
> How do I use python to do this, or do I just have to write a zsh
> script?
>


SSH takes measures to ensure that passwords are typed from a keyboard
(pty) rather than being piped in automatically (stdin).

If SSH public key authentication (see ssh-keygen) doesn't work for
you, then try ssh agent (see, ssh-add), "sshpass", or something like
"empty-expect".

If you use ssh public keys, you can also setup the public key so that
only a specified command can be run, and that the public key can only
be used from a specific host. This is more secure. See this page for
more info: http://troy.jdmz.net/rsync/index.html

Otherwise you may need to do some pty-hackery in python to fool ssh
into thinking it's password is being entered from a keyboard and not a
script. However, you should try public key authentication (with rsync
as the only allowed command) first.

Another method is to setup an ssh service on the server (perhaps in
inetd). One disadvantage of this is that the rsync session (including
rsync login passwords) is not encrypted.
 
Reply With Quote
 
David
Guest
Posts: n/a
 
      10-07-2007
Typo.

> Another method is to setup an ssh service on the server (perhaps in


Should be:

> Another method is to setup an rsync service on the server (perhaps in

 
Reply With Quote
 
Michael Torrie
Guest
Posts: n/a
 
      10-07-2007
timw.google wrote:
> Hi
>
> I want to write a python script that runs rsync on a given directory
> and host. I build the command line string, but when I try to run
> subprocess.call(cmd), or p=subprocess.Popen(cmd, shell=True),or
> os.system(cmd), I get prompted for my login password. I expected this,
> but when I try to give my password, it's echoed back to the terminal
> and the special characters in the password is (I think) getting
> interpreted by the shell (zsh)
>
> I can't ssh w/o supplying a password. That's the way the security is
> set up here.
>
> How do I use python to do this, or do I just have to write a zsh
> script?


You need to use the pexpect module.

>
> Thanks.
>


 
Reply With Quote
 
Nicholas Bastin
Guest
Posts: n/a
 
      10-08-2007
On 05 Oct 2007 16:23:50 GMT, Stargaming <(E-Mail Removed)> wrote:
> On Fri, 05 Oct 2007 08:37:05 -0700, timw.google wrote:
> >> I can't ssh w/o supplying a password. That's the way the security is
> >> set up here.
> >>
> >> How do I use python to do this, or do I just have to write a zsh
> >> script?
> >>
> >> Thanks.

> >
> > I wrote a zsh script to do what I wanted, but I'd still like to know how
> > to do it in Python.

>
> `subprocess.Popen` has a keyword argument called `stdin` -- what takes
> the password, I guess. Assigning `subprocess.PIPE` to it and using
> `Popen.communicate` should do the trick.


SSH doesn't read passwords off of stdin. If you want to supply a
password to SSH, then you need to control a pty directly.

--
Nick
 
Reply With Quote
 
timw.google
Guest
Posts: n/a
 
      10-09-2007
On Oct 7, 1:01 pm, Michael Torrie <(E-Mail Removed)> wrote:
> timw.google wrote:
> > Hi

>
> > I want to write a python script that runs rsync on a given directory
> > and host. I build the command line string, but when I try to run
> > subprocess.call(cmd), or p=subprocess.Popen(cmd, shell=True),or
> > os.system(cmd), I get prompted for my login password. I expected this,
> > but when I try to give my password, it's echoed back to the terminal
> > and the special characters in the password is (I think) getting
> > interpreted by the shell (zsh)

>
> > I can't ssh w/o supplying a password. That's the way the security is
> > set up here.

>
> > How do I use python to do this, or do I just have to write a zsh
> > script?

>
> You need to use the pexpect module.
>
>
>
> > Thanks.


Thanks to all the suggestions on getting this to work w/ python. I'll
look into this more when I get the chance. I don't have root access,
so setting up some kind of server is out. I may not be able to try the
other suggestions either, as they have things locked down pretty tight
around here.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
supplying runtime parameter sp XML 3 01-27-2006 08:42 AM
Problem writing cookie when supplying Path property =?Utf-8?B?U3llZCBHaGF5YXM=?= ASP .Net 2 05-06-2005 03:55 PM
supplying constants in an extension module Torsten Mohr Python 1 01-17-2005 09:23 PM
Making function private/ not supplying declaration in header file Daniel Nichols C Programming 6 06-15-2004 05:03 AM
Making function private/ not supplying declaration in header file Daniel Nichols C Programming 5 06-15-2004 03:38 AM



Advertisments