fabric keeps asking for password

2019-07-04 00:03发布

I have fab file which contains

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 am constantly prompt for [localhost] Login password for 'code':

I am running this on an ec2 instance to which I am connecting via ssh using key, and password login for ssh is disabled

EDIT: I think fabric is first doing ssh code@localhost but that wont work since password sshing is disabled

2条回答
乱世女痞
2楼-- · 2019-07-04 00:30

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

This would look something like this:

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

This solution will circumvent the login password prompt of your local machine. Of course, you'd have to do this for each local machine where you run your fabfile on.

查看更多
疯言疯语
3楼-- · 2019-07-04 00:46

The run() and sudo() operations are carried out via ssh. If you want to run a command on the localhost you should look into using local() instead:

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

On that same page are the docs for run() and sudo() which both refer to the fact they run on a "remote host" which infers that they will be run via ssh.

查看更多
登录 后发表回答