- Gitolite Essentials
- Sitaram Chamarty
- 1056字
- 2021-07-16 12:10:06
Setting up Gitolite
Now that the code is in the right place, we need to set it up. Setting it up involves adding an ssh public key for the main administrator of the Gitolite installation. In this book, we will assume the administrator's name is Adam, thus his Gitolite username will be adam
, but as you follow along, please substitute your own name wherever you see references to Adam or adam
.
Ssh is a powerful and complex tool. To make things simpler in this chapter, we will describe a set of steps that would surely work, along with suitable assumptions and constraints. These constraints are not absolutely necessary, but they do serve to simplify our procedure, as well as remove potential troublespots. If you're very familiar with SSH, you will probably be able to get around them quite easily.
Creating an ssh key pair
The administrator needs to first create an ssh key pair for themselves at their main workstation. In many cases, there may already be an ssh key pair, possibly generated for some other purpose. You should look in $HOME/.ssh
for a pair of files called id_rsa
and id_rsa.pub
. If you don't find any such files, you can generate a key pair by running the ssh-keygen
command.
Ideally, you will choose a strong passphrase to protect your private key when generating your ssh key pair. To use it without having to constantly type the passphrase, you will then use the ssh-agent
command or any of its derivatives, such as the keychain package. However, these nuances are out of the scope of this book.
Similarly, if you had previously created a non-default key type (that is, something other than RSA for ssh protocol 2, which is the default), then it is assumed that you know what you are doing. Gitolite should work fine with DSA and ECDSA key pairs, but will probably not work with RSA protocol 1 keys.
Running the setup command
Now that you have your key pair at your workstation, you will need to get the public key (and only the public key!) over to the Gitolite hosting user's home directory on the server. One way to do this is to use the scp
command, as in scp .ssh/id_rsa.pub git@host:adam.pub
. You can use any other method available to you, for example rsync, or sftp, or even a USB stick. It doesn't matter how you do it as long as the file gets there and is renamed as adam.pub
.
A word of warning for ssh experts: do not be tempted to automatically add this key to the Gitolite hosting user's authorized keys file using a command such as ssh-copy-id
.
Once you have copied the file, you are ready to run the actual setup command, which is as follows:
gitolite setup -pk adam.pub
This command should produce an output similar to the following:
Initialized empty Git repository in /home/gitolite-test/repositories/gitolite-admin.git/ Initialized empty Git repository in /home/gitolite-test/repositories/testing.git/ WARNING: /home/gitolite-test/.ssh/authorized_keys missing; creating a new one
You can ignore the warning about the authorized keys file being created—this is quite normal for the first time you do this. And with that, your Gitolite installation and setup are all done.
Checking over your new Gitolite server
Very few Gitolite administration tasks require logging on to the server and using the command line. Most of the day-to-day maintenance tasks (especially adding users and repositories) are done by making changes to a special repository called gitolite-admin
, and pushing those changes to the server; that is, the administrator must perform the following:
- Clone the
gitolite-admin
repository. - Add some files or make changes to existing files.
- Commit the changes.
- Push them to the server (an administrator is someone who is allowed to push to the
gitolite-admin
repo). When the push completes, Gitolite on the server side invokes specific scripts to effect the changes requested.
You should be able to clone the gitolite-admin repository from your workstation by running git clone
git@server:gitolite-admin
. Git will use ssh to connect to the "git" user on the "server". By default, it will look at your $HOME/.ssh
directory, find your ssh key pair, and offer the public key to the server to authenticate you. After that, things proceed pretty much as described in the earlier section on distinguishing users from each other, and Gitolite gives you access to the repository.
You should now see the usual message from a successful git clone
operation, and you can enter cd gitolite-admin
to see what came in:
$ cd gitolite-admin $ ls -a . .. conf .git keydir $ ls -a conf keydir conf: . .. gitolite.conf keydir: . .. adam.pub
You can see where the public keys are stored. Note that Gitolite's notion of what your Gitolite username is, comes solely from the name of the public key file in the keydir
directory. This is why when you copied the id_rsa.pub
file from your workstation you copied it as adam.pub
.
Tip
Ssh experts may note that the comment field inside the public key file is ignored; it would be against the conventional meaning of the word "comment" to use it for anything that causes a behavioral change in a system, despite the number of people on the Internet who appear to think it has a higher purpose.
Adding a user
Although we will cover adding users in detail in a later chapter, you may want to add a beta user right away. Let's say you want to add Bob; here's how you can do this:
- Get his public key, rename it to
bob.pub
. - Copy it to the
keydir
directory you saw above (that is, in your local clone of thegitolite-admin
repository). - Add the file, commit, and push.
Adding a repository
Looking inside the conf/gitolite.conf
file shows us the following:
$ cat conf/gitolite.conf repo gitolite-admin RW+ = adam repo testing RW+ = @all
To add a new repository, edit this file and add a repo line similar to the ones that were added previously, followed by an access rule line, sticking to the syntax shown previously for now. Save the file, add it, commit the change, and push the commit. You should immediately see the usual response from the remote git for a successful push, but also something like the following:
remote: Initialized empty Git repository in /home/gitolite-test/repositories/t2.git/
This indicates that the new repository is ready for use.
- 機(jī)器學(xué)習(xí)實(shí)戰(zhàn):基于Sophon平臺(tái)的機(jī)器學(xué)習(xí)理論與實(shí)踐
- 計(jì)算機(jī)應(yīng)用復(fù)習(xí)與練習(xí)
- Learning Apache Spark 2
- MCSA Windows Server 2016 Certification Guide:Exam 70-741
- PHP開發(fā)手冊(cè)
- 21天學(xué)通Java
- 系統(tǒng)安裝與重裝
- 網(wǎng)絡(luò)綜合布線設(shè)計(jì)與施工技術(shù)
- Splunk Operational Intelligence Cookbook
- 網(wǎng)絡(luò)化分布式系統(tǒng)預(yù)測(cè)控制
- Red Hat Linux 9實(shí)務(wù)自學(xué)手冊(cè)
- Hands-On Data Warehousing with Azure Data Factory
- Windows 7故障與技巧200例
- 計(jì)算機(jī)硬件技術(shù)基礎(chǔ)(第2版)
- Microsoft System Center Data Protection Manager Cookbook