Interaction with the shell

Erik Max Francis max at alcyone.com
Fri Jan 31 23:19:18 EST 2003


Tyson Tate wrote:

> I'd like to enter the password from within the code (i.e. so that the
> user doesn't enter the password). How might I do this? The man pages
> on
> ssh don't say that there are any parameters through which I can supply
> the password.

As well there shouldn't be; your password would then be visible to
anyone with an account on the same machine while you were using it (or
at least there would be a race condition for it to be visible).

You could probably use something like the PyExpect module (which I've
never had the pleasure to use myself):

	https://sourceforge.net/projects/pexpect/

A much better idea, though, is to avoid the password entirely and
instead set up a local ssh key with ssh-keygen and add the public key to
~/.ssh/authorized_keys on the remote system.  This will obviate the need
for a password exchange.

The problem is that even if you get it working with your password, that
password is either going to be passed as a command line into your Python
script (again, same problem as above) or is going to appear somewhere in
your Python file.  Now there's a text file somewhere on your system that
contains your password on another machine:  Bad idea.

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ The basis of optimism is sheer terror.
\__/ Oscar Wilde
    Bosskey.net / http://www.bosskey.net/
 A personal guide to online multiplayer first person shooters.




More information about the Python-list mailing list