Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Python

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

 

 

Python python RSS feed   Index | Next | Previous | View Threaded


tjandacw at yahoo

Oct 5, 2007, 7:33 AM

Post #1 of 9 (6614 views)
Permalink
supplying password to subprocess.call('rsync ...'), os.system('rsync ...')

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.

--
http://mail.python.org/mailman/listinfo/python-list


tjandacw at yahoo

Oct 5, 2007, 8:37 AM

Post #2 of 9 (6457 views)
Permalink
Re: supplying password to subprocess.call('rsync ...'), os.system('rsync ...') [In reply to]

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.

--
http://mail.python.org/mailman/listinfo/python-list


stargaming at gmail

Oct 5, 2007, 9:23 AM

Post #3 of 9 (6468 views)
Permalink
Re: supplying password to subprocess.call('rsync ...'), os.system('rsync ...') [In reply to]

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
--
http://mail.python.org/mailman/listinfo/python-list


ldo at geek-central

Oct 6, 2007, 1:18 AM

Post #4 of 9 (6448 views)
Permalink
Re: supplying password to subprocess.call('rsync ...'), os.system('rsync ...') [In reply to]

In message <1191594819.381604.20680 [at] o80g2000hse>,
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.

--
http://mail.python.org/mailman/listinfo/python-list


wizzardx at gmail

Oct 7, 2007, 1:43 AM

Post #5 of 9 (6442 views)
Permalink
Re: supplying password to subprocess.call('rsync ...'), os.system('rsync ...') [In reply to]

On 10/5/07, timw.google <tjandacw [at] yahoo> 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.
--
http://mail.python.org/mailman/listinfo/python-list


wizzardx at gmail

Oct 7, 2007, 1:51 AM

Post #6 of 9 (6443 views)
Permalink
Re: supplying password to subprocess.call('rsync ...'), os.system('rsync ...') [In reply to]

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
--
http://mail.python.org/mailman/listinfo/python-list


torriem at chem

Oct 7, 2007, 10:01 AM

Post #7 of 9 (6437 views)
Permalink
Re: supplying password to subprocess.call('rsync ...'), os.system('rsync ...') [In reply to]

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.
>

--
http://mail.python.org/mailman/listinfo/python-list


nick.bastin at gmail

Oct 7, 2007, 5:37 PM

Post #8 of 9 (6449 views)
Permalink
Re: supplying password to subprocess.call('rsync ...'), os.system('rsync ...') [In reply to]

On 05 Oct 2007 16:23:50 GMT, Stargaming <stargaming [at] gmail> 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
--
http://mail.python.org/mailman/listinfo/python-list


tjandacw at yahoo

Oct 9, 2007, 8:06 AM

Post #9 of 9 (6432 views)
Permalink
Re: supplying password to subprocess.call('rsync ...'), os.system('rsync ...') [In reply to]

On Oct 7, 1:01 pm, Michael Torrie <torr...@chem.byu.edu> 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.

--
http://mail.python.org/mailman/listinfo/python-list

Python python RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.