Home » Coding » Python » supplying password to subprocess.call('rsync ...'), os.system('rsync ...')
supplying password to subprocess.call('rsync ...'), os.system('rsync ...') [message #15347] Fri, 05 October 2007 10:33 Go to next message
tjandacw  is currently offline tjandacw
Messages: 4
Registered: September 2007
Junior Member
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.
Re: supplying password to subprocess.call('rsync ...'), os.system('rsync ...') [message #15374 is a reply to message #15347 ] Fri, 05 October 2007 11:37 Go to previous messageGo to next message
tjandacw  is currently offline tjandacw
Messages: 4
Registered: September 2007
Junior Member
On Oct 5, 10:33 am, "timw.google" <tjand...@yahoo.com> 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.
Re: supplying password to subprocess.call('rsync ...'),os.system('rsync ...') [message #15397 is a reply to message #15347 ] Fri, 05 October 2007 12:23 Go to previous messageGo to next message
Stargaming  is currently offline Stargaming
Messages: 17
Registered: August 2007
Junior Member
On Fri, 05 Oct 2007 08:37:05 -0700, timw.google wrote:

> On Oct 5, 10:33 am, "timw.google" <tjand...@yahoo.com> 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
Re: supplying password to subprocess.call('rsync ...'), os.system('rsync ...') [message #15504 is a reply to message #15347 ] Sat, 06 October 2007 04:18 Go to previous messageGo to next message
ldo  is currently offline ldo
Messages: 150
Registered: August 2007
Senior Member
In message <1191594819.381604.20680@o80g2000hse.googlegroups.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.
Re: supplying password to subprocess.call('rsync ...'), [message #15618 is a reply to message #15347 ] Sun, 07 October 2007 04:43 Go to previous messageGo to next message
David[1]  is currently offline David[1]
Messages: 43
Registered: September 2007
Member
On 10/5/07, timw.google <tjandacw@yahoo.com> 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.
Re: supplying password to subprocess.call('rsync ...'), [message #15622 is a reply to message #15347 ] Sun, 07 October 2007 04:51 Go to previous messageGo to next message
David[1]  is currently offline David[1]
Messages: 43
Registered: September 2007
Member
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
Re: supplying password to subprocess.call('rsync ...'), [message #15798 is a reply to message #15347 ] Sun, 07 October 2007 13:01 Go to previous messageGo to next message
Michael L Torrie  is currently offline Michael L Torrie
Messages: 5
Registered: August 2007
Junior Member
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.
>
Re: supplying password to subprocess.call('rsync ...'), [message #17450 is a reply to message #15347 ] Sun, 07 October 2007 20:37 Go to previous message
Nicholas Bastin  is currently offline Nicholas Bastin
Messages: 7
Registered: October 2007
Junior Member
On 05 Oct 2007 16:23:50 GMT, Stargaming <stargaming@gmail.com> 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
Previous Topic:Cross platform way of finding number of processors on a machine?
Next Topic:Re: Problem using subprocess.Popen on windows
Goto Forum:
  


Current Time: Fri May 16 02:38:52 EDT 2008

Total time taken to generate the page: 0.49599 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 2.7.7.
Copyright ©2001-2007 FUD Forum Bulletin Board Software