Here is the steps to run git private server on XigmaNAS.
- Install git package
- Create “git” account
- Set up git directory
- Set up the ssh public key auth for easy login
I know I can do this from the XigmaNAS web GUI’s command but it’s too tedious so please use the terminal of your choice. You also need a text editor most likely. MYVOLUME should be your data store of choice.
# pkg install -y git
# GITHOME=/mnt/MYVOLUME/git
# mkdir -p $GITHOME/projects
# mkdir -p $GITHOME/.ssh
# cd $GITHOME/.ssh
# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): mygit_rsa
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in mygit_rsa.
Your public key has been saved in mygit_rsa.pub.
The key fingerprint is:
# cat mygit_rsa.pub >> authorized_keys
# chmod 600 authorized_keys
Now, you need to create “git” account. From XigmaNAS UI, Access>User&Groups, first go to Groups and add “git” group. GID can be anything so I picked a random number 3178. Then, create “git” user.
So the “git-shell”. Unfortunately, the shell selection is not picked up from /etc/shells. I sniffed around and you need to hack the php file for this to show up. You need to be root to edit the PHP file. The file is /usr/local/www/access_users_edit.php
so become root and open it with a text editor. Look for $l_shell. Add a line for git-shell. Snippet and diff follow. I use ksh a lot so I added ksh as an option as well.
/etc/inc/system/access/user/grid_properties.php
contains the list of shells.
$l_shell = [
'nologin' => 'nologin',
'scponly' => 'scponly',
'sh' => 'sh',
'bash' => 'bash',
'csh' => 'csh',
'tcsh' => 'tcsh',
'ksh' => 'ksh',
'git-shell' => 'git-shell'
];
*** access_users_edit.php.orig 2018-11-11 05:43:42.000000000 +0000
--- access_users_edit.php 2019-06-01 20:14:57.350303000 +0000
***************
*** 239,245 ****
'sh' => 'sh',
'bash' => 'bash',
'csh' => 'csh',
! 'tcsh' => 'tcsh'
];
html_radiobox2('shell',gettext('Shell'),$pconfig['shell'],$l_shell,gettext('Set user login shell.'),true);
$l_grouplist = [];
--- 239,247 ----
'sh' => 'sh',
'bash' => 'bash',
'csh' => 'csh',
! 'tcsh' => 'tcsh',
! 'ksh' => 'ksh',
! 'git-shell' => 'git-shell'
];
html_radiobox2('shell',gettext('Shell'),$pconfig['shell'],$l_shell,gettext('Set user login shell.'),true);
$l_grouplist = [];
Reloading the user setting page should bring up the git-shell for shell selection. Now you need to go back to the terminal and finish the set up.
# cd $GITHOME
# mkdir projects
# chown -r git:git $GITHOME
# chmod 775 projects
As a git server, all set. The remaining thing is to add “git” group to the users on the server so users can create new repo under projects, and handing out the private key mygit_rsa to users, or add the public key to the authorized_keys of “git” user.
Example:
Let’s say I want to have a “config.git” on the server. This repo stores all my Linux machine’s configuration files so when I have to set up a new machine, I can see how I set up my account in the past.
First, since I don’t know how to create fresh repo from client side, I will create a fresh repo on XigmaNAS.
Here is the steps:
- SSH-Login to NAS. Since “git” account is not shell account, you have to do this as root unfortunately.
- Create a repo directory “
mkdir $GITHOME/config.git
“ - Still as root,
cd $GITHOME/config.git && git init --bare
chown -R git:git $GITHOME/config.git
From the client side, now repo is ready, if you set up the ssh keys right, you do:git clone ssh://git@nas/~/config.git