Ubuntu – Cannot create directory: Permission denied

gitUbuntuvps

I'm trying for the first time to set up GIT on a VPS following this tutorial. Part of the instructions are:

cd /var
mkdir repo && cd repo
mkdir site.git && cd site.git
git init --bare

However, on mkdir repo I get cannot create directory ‘repo’: Permission denied. I'm logged into the VPS as a user with sudo rights. How can I find out the cause of the problem? I'm really new to this so am not sure what to report here.

Update: After solving the above by adding sudo to the command, I got a permission error on git push live master:

Counting objects: 709, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (665/665), done.
Writing objects: 100% (709/709), 103.57 KiB | 0 bytes/s, done.
Total 709 (delta 368), reused 0 (delta 0)
remote: fatal: Unable to create temporary file '/var/repo/site.git/./objects/pack/tmp_pack_XXXXXX': Permission denied
error: unpack failed: index-pack abnormal exit
To ssh://username@VPS_IP_ADRES/var/repo/site.git
 ! [remote rejected] 3.7-advanced-testing -> 3.7-advanced-testing (unpacker error)
etc.

I did skip a few steps of the tutorial because I already have GIT completely set up in Cloud9IDE (which I use for writing my app). This works and I can push to Heroku, which I now am trying to replace with a VPS. So what I have done from a situation with a working GIT: I did the four steps mentioned above, while logged into the VPS as superuser. Then, while logged in at Cloud9, I did git remote add live ssh://username@VPS_IP_ADRES/var/repo/site.git. And then git push -u live --all, which gave me the errors above. Any idea about there cause?

Best Answer

That tutorial is assuming you have superuser rights, so just use sudo su before you start running commands, or insert sudo before all the commands that require elevation.