Reputation: 3009
So, I'm creating a system which manages all the drupal websites that sit within a specific folder (new websites can be created in this folder).
The next step is to create a way to allow the user to revert the website to a prior version.
My solution? Create a local "git server" and for every action taken on my system (e.g.: update/install modules, upgrade the core, etc) I create a new version of that site.
I created a "git" user which is responsible for the creation of repositories on /~/gitrepos/
. And for each new website, I use sudo -u git
within apache user (www-data) to run mkdir
and git init --bare
. I'm currently able to create new folders and to initialize git repositories on those.
But when I try to push the website changes to those repositories, I get "Permission denied".
When a new site is detected, I do the following:
sudo -u git
]
mkdir
and git init
git init
git add *
git commit -m 'msg'
git remote add origin ssh://git@localhost/path/to/repo/
git push -u origin master
And now I'm stuck on this step, as I always get "Permission denied".
There's any way for me to push changes to a local "git server" without the need to authenticate?
Or yet, which ssh-keys I should create to enable www-data to push changes to the local "git server"?
I'm really lost here, if someone has a step-by-step way to setup a local "git server" in which the www-data user can push to, that would be great.
Note: the home directory for www-data is /var/www/
, so it's not a good idea to store ssh-keys in this directory
Yes, I have spent at least 4 hours trying to figure this out before asking here.
Some of the resources I tried to follow:
The reason why I quote "git server" is because there's no such thing as a git server.
Quote from http://blogs.gurulabs.com/aaron/2008/11/setup-a-git-repository.html :
In other words, there's no such thing as a "git server" and "git client". Git was developed by filesystem developers with filesystem attributes in mind. So, instead, we have a remote Git repository we call the "origin" and a local Git repository (...)
Upvotes: 0
Views: 6285
Reputation: 3009
Assumptions:
www-data
home directory is /var/www/
gituser
Steps:
To make the www-data
user push changes to the git repo without the need to type the password, just:
www-data:~$ ssh-keygen -t rsa
enter
for every question (leave the password blank)/home/gituser/.ssh/authorized_keys
gituser:~$ touch ~/.ssh/authorized_keys
gituser:~$ chmod 0600 ~/.ssh/authorized_keys
gituser:~$ cat /var/www/.ssh/id_rsa.pub >> /home/gituser/.ssh/authorized_keys
The idea behind that, is to add www-data
's ssh-key to gituser
's "trusted" keys. After that, www-data
will be able to connect to the server via ssh and authenticate as gituser
without the need to type the password.
Remember that git requires ssh access to the server (at least on the environment that I'm at).
This might help: http://www.linuxproblem.org/art_9.html
Upvotes: 2