Samuel Ellis Samuel Ellis - 5 months ago 23
Linux Question

How do I pull from a git repo on a remote machine through ssh?

I have several remote machines that need to pull from a repo after I've completed testing and ready to make updates to production (python Flask app and supporting classes). A couple of the machines need to pull from a different branch, as well. I've been SSHing to each machine to run the git pull, but this is getting annoying and time consuming.

I'm trying to run an ssh command that completes a git pull. This is what I've tried:

ssh dev@<remote IP> "cd /home/dev/<repo> && git pull"

And I'm getting a

Permission denied (publickey).
fatal: Could not read from remote repository.

I'm able to run other git commands just fine that don't interact with remote origin. Such as:

ssh dev@<remote IP> "cd /home/dev/<repo> && git remote -v"

When I actually ssh on to the remote machine. I have no problem navigating to the directory and running a git pull.

I also made sure that I added the ssh key to an ssh-agent so that password prompts on the key wouldn't be an issue.

Thought it could potentially be a key permissions issue, so I double checked that the key is readable by the user I'm running the command as.

It's frustrating that I am able to ssh on to the remote machine and run the pull just fine, but cannot run the command with the format above.

Thanks a ton for any help!


From what I understood with your issue, here is my suggestion : [ Information is somewhat incomplete though ]

GIT reads your in root user directory : /home/root/.ssh/

That's why your key in /home/your_username/.ssh/ might not be read by git.

Hence, please check and create the key in /home/root/.ssh/

$ sudo su
$ ssh-keygen
$ cd ~/.ssh
$ cat

Hope it helps.