From c3429a22b429bc29b376fef4dbe69c80695efcc4 Mon Sep 17 00:00:00 2001 From: ktyl Date: Sun, 16 Jan 2022 22:28:20 +0000 Subject: [PATCH] setting up a remote git server --- blogs/2022/1/16/git-server.md | 62 +++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 blogs/2022/1/16/git-server.md diff --git a/blogs/2022/1/16/git-server.md b/blogs/2022/1/16/git-server.md new file mode 100644 index 0000000..1966abb --- /dev/null +++ b/blogs/2022/1/16/git-server.md @@ -0,0 +1,62 @@ +# create a git user + +on debian, `sudo adduser git` + +switch to git user with `sudo su git` + +create a `.ssh` dir in the git user's home dir and make it only accessible by the git user + +``` +cd ~ && mkdir .ssh +chmod 700 .ssh +``` + +create an `authorized_keys` file in the `.ssh` folder, and make it accessible only by the git user + +``` +touch .ssh/authorized_keys +chmod 600 `.ssh/authorized_keys` +``` + +create a private/public key pair locally to authenticate a user on a machine to connect to the remote server + +``` +ssh-keygen -t dsa +``` + +and finally copy it to the (remote) git user's `.ssh/authorized_keys`, for example using `ssh-copy-id` or giving the public key to the server administrator. + +# creating bare git repositories + +create directories within git's home dir (nested paths are allowed) with the `.git` extension, for example `my-projects/my-repo.git` or just `my-repo.git`. + +``` +git init --bare repo.git +``` + +there now exists an empty git repository on the server. + +the remote can now be added to a local repository + +``` +git remote add origin git@server:my-repo.git +git push -u origin main +``` + +# connecting using the key + +add an entry to your local `.ssh/config` + +``` +Host myhost + HostName example.com + User git + IdentityFile ~/.ssh/id_rsa +``` + +and connect with + +``` +ssh myhost +``` +