There are several solutions to your problem. First, you want to run commands with sudo. You can use the cloth method sudoinstead run, which runs a shell command on a remote host, with superuser privileges( sudo ref ).
For example, these commands are executed using sudo:
sudo("~/install_script.py")
sudo("mkdir /var/www/new_docroot", user="www-data")
sudo("ls /home/jdoe", user=1001)
result = sudo("ls /tmp/")
, ( sudo ed).
Fabric (ref). , prefix settings.
:
with settings(user='root'):
run('do something')
run('do another thing')
, root root.
.