Saturday, August 28, 2021

HOWTO - Git server setup on ubuntu

ref:  https://git-scm.com/book/en/v2/Git-on-the-Server-Setting-Up-the-Server


1. create 'git' user and group



    $ sudo adduser git


2. create git users



    $ sudo useradd -M  adam # not create home directory

    $ sudo passwd  adam

    $ sudo usermod -G git  adam


    $ which git-shell


in /etc/passwd, replace /bin/bash with  /usr/bin/git-shell    # git-only ssh login



3. handle ssh keys


    $ su git
    $ cd
    $ mkdir .ssh && chmod 700 .ssh
    $ touch .ssh/authorized_keys && chmod 600 .ssh/authorized_keys 

    $ cat /tmp/id_rsa.adam.pub >> ~/.ssh/authorized_keys


4. create new project



    $ mkdir -p  /home/git

    $ chmod g-w /home/git        # make sure group has no write access

    $ cd /home/git

    $ git init --bare test.git

    $ chmod -R git:git test.git/ # double-check

    $ chmod -R 775 test.git/



# check project from user side


    $ git clone adam@serverip:/home/git/test.git

    $ cd test

    $ git remote -v

Labels: , , ,

Saturday, August 07, 2021

Git clone to replace a dead repo

A network machine hosting the git repo was dead.

The checkout still exists in local.

Setup a new machine, planning to use it as the new host for repo.



ssh  user@remote

cd /path/to/allprojects/root

git init --bare new_proj.git

exit


# at local

git remote set-url origin  user@remote:/path/to/allprojects/root/new_proj.git

git push --all origin



Labels: , , ,