how to execute the following command using python

Chris Angelico rosuav at
Thu Sep 25 14:42:19 CEST 2014

On Thu, Sep 25, 2014 at 10:28 PM,  <pradeepatjob at> wrote:
> echo -e 'ubuntumachinepassword/\nremotemachinepasword' | sudo --stdin sshfs root at remoteip:/remotesystem/folder/  /localmountpoint / -o workaround=rename -o password_stdin -o allow_other

This implies that you're embedding two passwords in the script, in
clear text. I suggest not doing this - it's actually easier that way.
All you need to do is permit passwordless access: first to sudo, then
to the remote machine.

Passwordless sudo access can be done either globally or for this one
specific password, via the sudoers file. You can find out how to do
that on the internet; it's not a Python issue. Passwordless SSH
(including sshfs) is usually done with a key pair - look up ssh-keygen
and the authorized_keys file (you put your public key into that file,
and access is granted without a password). Again, plenty of info about
that on the internet.

(Side point: I strongly recommend NOT granting access via the root
login. Even if you know what you're doing, even if you think you've
locked it down to just SFTP, even if you think it's granting read-only
access, I still say mounting root at anything is a dangerous thing to do.
And if you haven't locked it down, and are giving root shell access to
anyone who knows a password that's stored in clear text in a script...
you definitely shouldn't be doing that.)

Once you have that, all you need is to run this:

sudo sshfs root at remoteip:/remotesystem/folder /localmountpoint -o allow_other

and you might not even need "-o allow_other". Everything should just
work by itself - that's what I do with the Yosemite Project, with an
additional feature of automating the authorized_keys management (based
on IP address ranges that are permitted access).


More information about the Python-list mailing list