0

I'm working with fabric3 (https://pypi.python.org/pypi/Fabric3) , a python 3 port of fabric.

I have the following function wchich I'm running locally in win7 using git-bash:

@roles('production')
def dir():
    env.key_filename = '~/.ssh/deploy'
    local("git push mysite master")
    run('pwd')
    run('ls')
    code_dir = '/home/deploy/mysite'
    with cd(code_dir):
        run('pwd')
        run('git reset --hard master')
        run('ls -la')

output:

$ fab dir
[deploy@198.x.x.x] Executing task 'dir'
[localhost] local: git push mysite master
deploy@198.x.x.x's password:

When I run the function, I get asked for the password. It seems to be ignoring the key. How can I get the function to use the prescribed key?

user1592380
  • 34,265
  • 92
  • 284
  • 515
  • Is the password asked by `git push`? – Leon Feb 09 '17 at 17:26
  • yes it appears so. – user1592380 Feb 09 '17 at 17:30
  • `git push` executed from under `fabric` connects to the remote host using a separate connection that is not managed by `fabric`. – Leon Feb 09 '17 at 17:38
  • Because git uses the ssh-agent, you will need to run something like this. [Specify private SSH-key to use when executing shell command with or without Ruby?](http://stackoverflow.com/questions/4565700/specify-private-ssh-key-to-use-when-executing-shell-command-with-or-without-ruby) – Matt Clark Feb 09 '17 at 17:48

1 Answers1

0

I added git as a user to my .ssh/config file and it now appears to work.

Host deploy
HostName 198.x.x.x
User deploy
PreferredAuthentications publickey
IdentityFile ~/.ssh/deploy
IdentitiesOnly yes

Host 198.x.x.x
HostName 198.x.x.x
User git
IdentityFile ~/.ssh/deploy
user1592380
  • 34,265
  • 92
  • 284
  • 515