Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Permission denied on git repository with Fabric

Tags:

git

python

fabric

I'm writing a fab script to do a git pull on a remote server, but I get Permission denied (publickey,keyboard-interactive). when fabric runs the command.

If I ssh to the server and then do the pull, it works. (I've already setup the keys on the server, so it doesn't ask for passphrases, etc.)

Here's my fabric task:

import fabric.api as fab
def update():
  '''
  update workers code
  '''
  with fab.cd('~/myrepo'):
      # pull changes
      print colors.cyan('Pulling changes...')
      fab.run('git pull origin master')

How do I get it to work with Fabric?

Edit: My server is a Google Compute instance, and it provides a gcutil tool to ssh to the instance. This is the command it runs to connect to the server:

ssh -o UserKnownHostsFile=/dev/null -o CheckHostIP=no -o StrictHostKeyChecking=no -i /Users/John/.ssh/google_compute_engine -A -p 22 [email protected] 

The script is able to connect to the server AFAICT (it's able to run commands on the server like cd and supervisor and git status), it's just git pull that fails.

like image 753
john2x Avatar asked Nov 18 '25 13:11

john2x


1 Answers

you need to edit fabfile like this in order to enable ssh agent fowarding option.

from fabric.api import *

env.hosts = ['123.456.789.101']
env.user = 'John'
env.key_filename = '/Users/John/.ssh/google_compute_engine'
env.forward_agent = True

def update():
  '''
  update workers code
  '''
  with cd('~/myrepo'):
      # pull changes
      print colors.cyan('Pulling changes...')
      run('git pull origin master')
like image 79
Yuichiro Avatar answered Nov 21 '25 02:11

Yuichiro



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!