Fabric: allow specification of '-H' (set HOME) to sudo

Created on 4 Sep 2011  ·  2Comments  ·  Source: fabric/fabric

Without the -H flag to the sudo command, calls to pip may fail when run through sudo because HOME is still set to the SSH username, rather than the sudo username. This is required, e.g., for writing an error log in the case that a package build fails.

Either set this by default, or provide an argument to sudo() that will enable it on the remote sudo command.

Bug Feature sudo()

Most helpful comment

I got bitten by this, too. Despite 'env_reset' being set in ubuntu's default sudoers file, HOME isn't being set to the user you sudo to... Before it ends up in fabric itself, there's an easy way to set the '-H' option always. Near the top of your fabfile, set this:

env['sudo_prefix'] += '-H '

All 2 comments

I got bitten by this, too. Despite 'env_reset' being set in ubuntu's default sudoers file, HOME isn't being set to the user you sudo to... Before it ends up in fabric itself, there's an easy way to set the '-H' option always. Near the top of your fabfile, set this:

env['sudo_prefix'] += '-H '

I'm going to fold this into #503, no point having 2x discussions on it.

@tobiasmcnulty and @reinout I have a comment over on #503 re: use of -i instead of -H, if you have any feedback for that, please leave some :)

Was this page helpful?
0 / 5 - 0 ratings