blog/blogs/unfinished/git/git-server.md

63 lines
1.3 KiB
Markdown
Raw Normal View History

2022-01-16 23:28:20 +01:00
# create a git user
on debian, `sudo adduser git`
2022-04-05 01:33:35 +02:00
switch to git user with `sudo su -l git`
2022-01-16 23:28:20 +01:00
create a `.ssh` dir in the git user's home dir and make it only accessible by the git user
```
2022-04-05 01:33:35 +02:00
mkdir ~/.ssh
chmod 700 ~/.ssh
2022-01-16 23:28:20 +01:00
```
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
```
2022-04-05 01:33:35 +02:00
ssh-keygen -t rsa
2022-01-16 23:28:20 +01:00
```
2022-04-05 01:33:35 +02:00
and finally copy it into the (remote) git user's `.ssh/authorized_keys`, for example using `ssh-copy-id` or giving the public key to the server administrator.
2022-01-16 23:28:20 +01:00
# 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
```