I have tried following how-set-up-your-own-private-git-server-linux and private-remote-git-repositories-ubuntu-linode but I am still having problems.
My local environmen
I followed the most voted answer and I didnt get it to work. I found this tutorial: https://www.digitalocean.com/community/tutorials/how-to-set-up-ssh-keys--2 and I got it working. I think the problem was that, in the server, the public key is to be copied to a file "authorized_keys" and not "authorized_hosts".