Fabric continues to ask for a password

I have a fab file containing

env['hosts'] = ['localhost'] env['user'] = 'code' env['password'] = 'searce' def mk_dirtree(): sudo("mkdir %s" % PROJECT_DIR) sudo("chown -R code:code %s" % PROJECT_DIR) run("mkdir -p %s" % (PROJECT_DIR + '/www/static')) sudo("chown -R www-data:www-data %s" % (PROJECT_DIR + '/www')) 

now when i do fab mk_dirtree I constantly ask for [localhost] Login password for 'code':

I run this on an ec2 instance, to which I connect via ssh using a key, and the password for ssh is disabled

EDIT: I think the fabric first does ssh code@localhost , but this does not work as sshing password is disabled

+3
python ssh fabric
source share
2 answers

If you really need and need to use run() instead of local() , you can add your public SSH key to the ~/.ssh/authorized_keys file of your user account.

It will look something like this:

 cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys 

This solution will cost you a password to enter the local computer. Of course, you will need to do this for each local machine on which you run the file.

+4
source share

The run() and sudo() operations are performed via ssh. If you want to run the command on localhost, you should look for local() instead:

http://docs.fabfile.org/en/1.4.3/api/core/operations.html?highlight=sudo#fabric.operations.local

On the same page are documents for run() and sudo() , which relate to the fact that they run on a "remote host", which indicates that they will be executed via ssh.

+1
source share

All Articles