Configure git in ubuntu

Source: Internet
Author: User
I have been tossing the git version management server for several days after configuring git in ubuntu. I feel a little too large, and I don't have enough permissions in a moment. the encrypted file does not match the username & hellip; however, this afternoon has always been an effective task. I will record the errors and errors I have encountered over the past few days and give them to you...
I have been tossing the git version management server for several days after configuring git in ubuntu. I feel a little too large, and I don't have enough permissions in a moment. the encrypted file does not match the user name in a while ...... However, this afternoon has always been an effective task. I will record the errors I have encountered over the past few days and give them a reference! Today, I modified the log again, mainly to solve the gitweb display problem, and the new member cannot clone the git repository! Hardware Requirements for www.2cto.com 1: A Ubuntu or debian computer (Virtual Machine) can be accessed through the network. Software Requirements: git-core, gitosis, openssh-server, openssh-client2 installation configuration git server installation git and openssh: a @ server :~ $ Sudo apt-get install git-core openssh-server openssh-client newly added User git, which serves as the administrator of all code repositories and user permissions: a @ server :~ $ Sudo useradd-m gita @ server :~ $ Sudo passwd git
Create a git repository storage point: a @ server :~ $ Sudo mkdir/home/repo: This directory does not have any permissions for users other than git: a @ server :~ $ Sudo chown git: git/home/repoa @ server :~ $ Sudo chmod 755/home/repo note: Set the repo attribute of the git repository to 755. Otherwise, the project cannot be found in gitweb.
3. install and configure gitosis to initialize the git User on the server. This step is actually in preparation for installing gitosis. To use git on any machine, you must initialize it for the first time: a @ server :~ $ Git config-global user. name "myname" a @ server :~ $ Git config-global user. email "myname @ server" install python's setup tool, which is also prepared for gitosis: a @ server :~ $ Sudo apt-get install python-setuptools get gitosis package: www.2cto.com a @ server :~ $ Cd/tmpa @ server:/tmp $ git clone git: // eagain.net/gitosis.gita@server:/tmp$ cd gitosisa @ server:/tmp/gitosis $ sudo python setup. py install
Switch to git User: a @ server:/tmp/gitosis $ su git by default, gitosis will put the git repository under the git User's home, so we make a link to/home/repo $ ln-s/home/repo/home/git/repositories and return to the default user $ exit again if you will be the administrator of the git server, then, you can generate an ssh public key (usr @ pc1: ~) on your computer (another pc :~ $ Ssh-keygen-t rsa: Copy the public key to the/tmp Directory of the server: usr @ pc1 :~ $ Scp. ssh/id_rsa.pub git @ :/Tmp return to the git server a @ server:/tmp/gitosis $ sudo chmod a + r/tmp/id_rsa.pub to run gitosis: a @ server: /tmp/gitosis $ sudo-H-u git gitosis-init </tmp/id_rsa.pubInitialized empty Git repository in/home/repo/gitosis-admin.git/Reinitialized existing Git repository in/home/repo/ what's interesting about gitosis-admin.git/gitosis is that, it manages the configuration file through a git repository, which is stored in/home/repo/gitosis-admin. git. We need to add executable permissions to a file: a @ server:/home/git $ sudo passwd roota @ server:/home/git $ suroot @ server: /home/git # cd repositoriesroot @ server:/home/git/repositories # cd gitosis-admin.git/root @ server: /home/git/repositories/gitosis-admin.git # sudo chmod 755/home/repo/gitosis-admin.git/hooks/post-updateroot @ server:/home/git/repositories/gitosis-admin.git # exit
4. create a new test project warehouse on the server. we create an empty project warehouse named "teamwork" on the server ". Switch to git User: www.2cto.com a @ server:/home/git $ su-git $ cd/home/repo $ mkdir teamwork. git $ cd teamwork. git $ git init--bare note: this is run on the server to initialize a root-level git repository $ exit. however, so far, this is only an empty repository, empty warehouses cannot be cloned. To clone a database, you must first release an initialized version to the repository. So, we must first modify the gitosis-admin.5 management gitosis configuration file just mentioned that gitosis's own configuration is also achieved through git. In your own development machine, clone the gitosis-admin.git warehouse, you can modify the configuration as administrator. In your computer: usr @ pc1 :~ /Work $ git clone git @ Gitosis-admin.gitusr @ pc1 :~ /Work $ cd gitosis-admin/The keydir directory under this directory is used to store the ssh public keys of all users who need to access the git server: each user generates their own ssh public key file according to the method mentioned above, takes all the ssh public key files and names them by name, such as B. pub, lz. pub and so on, all copies to the keydir: usr @ pc1 :~ /Work/gitosis-admin $ su rootroot @ pc1:/home/a/work/gitosis-admin # cp/path//. ssh/id_rsa.pub. /keydir/B. pubroot @ pc1:/home/a/work/gitosis-admin # exit to modify gitosis. conf file. my configuration is roughly as follows: [gitosis] [group gitosis-admin] writable = gitosis-adminmembers = a @ server usr @ pc1 [group hello] writable = teamworkmembers = a @ server B [group hello_ro] readonly = teamworkmembers = lz: members of the gitosis-admin group have a and usr, which are -The admin warehouse has read and write permissions. the www.2cto.com team group has members a and B. The team has read and write permissions on the teamwork warehouse. the team_ro group has one lz member and the team work warehouse has read-only permissions. Of course, the modifications to these configuration files are only made locally. you must push them to the remote gitserver to make the changes take effect. Add a new file, submit it, and push it to the git server: usr @ pc1 :~ /Work/gitosis-admin $ git add. usr @ pc1 :~ /Work/gitosis-admin $ git commit-am "add teamweok prj and users" usr @ pc1 :~ /Work/gitosis-admin $ git push origin master
6. the test project has been initialized. now the server has been set up, and an empty Project teamwork is on the server. What about next? Of course it is a test. empty warehouse cannot be cloned, so a person with write permission needs to initialize a version. Let me do it. The following is done on the client. Usr @ pc1 :~ /Work $ mkdir teamwork-oriusr @ pc1 :~ /Work $ cd teamwork-ori/usr @ pc1 :~ /Work/teamwork-ori $ git init note: this is executed on the client PC, in order to initialize a local version Library usr @ pc1 :~ /Work/teamwork-ori $ echo "/* add something */"> hellousr @ pc1 :~ /Work/teamwork-ori $ git add. usr @ pc1 :~ /Work/teamwork-ori $ git commit-am "initial version" usr @ pc1 :~ /Work/teamwork-ori $ git remote add origin git @ : Teamwork. gitusr @ pc1 :~ /Work/teamwork-ori $ git push origin master so far teamwork already has a version. other members of the team only need to clone the teamwork warehouse first and can play it freely. Usr @ pc1 :~ /Work/teamwork-ori $ su B $ cd/home/B $ git clone git @ : Teamwork. git $ cd teamwork www.2cto.com $ vim hello $ git add. $ git commit-am "B add" $ git push origin master $ exit
7. add an existing git project. if you have a ready-made git repository and want to put it on the gitserver for use by the team (for example, you clone an official kernel Repository, what should I do if I want to use it internally as the basic repository. First, you need to get a pure repository from your work warehouse. for example, your work directory is ~ /Kernel: you want to export the pure repository to your USB flash drive and copy it to gitserver. $ Git clone-bare ~ /Kernel/media/udisk, then take the USB flash drive and hand it to the gitserver administrator to copy it to/home/repo/and configure gitosis configuration files, you don't need to talk about this anymore. For example, download the ALSA Library: git clone git: // android.git.kernel.org/platform/external/alsa-lib.gitgit clone git: // export clone-bare alsa-lib alsa-lib.gitgit clone-bare alsa-utils alsa-utils.git move the bare library to the git server directory cp alsa-lib.git/home/repo pay attention to changing the owner to get commit permissions. Chown-R git alsa-lib.git and then O, huh.
8. create gitwebsudo apt-get install gitweb8.1. configure gitweb without css loading by default. connect the static files to be used by gitweb to DocumentRoot: cd/var/www/sudo ln-s/usr/share/gitweb /*. 8.2 modify and configure sudo vi/etc/gitweb. conf changes $ projectroot to the git repository storage directory (for example,/home/git/repositories) and refresh the browser. If no project is found, you need to change the $ projectroot/*. git attribute to 755 so that apache users have the permission to read. You can only change the git that you want others to access through the web. Http: // localhost/cgi-bin/gitweb. cgi8.3 modify/etc/gitweb. conf # path to git projects ( . Git) # $ projectroot = "/var/cache/git"; $ projectroot = "/home/git/repositories "; # directory to use for temp files $ git_temp = "/tmp"; www.2cto.com # target of the home link on top of all pages $ home_link = $ my_uri | "/"; # html text to include at home page $ home_text = "indextext.html"; # file with project list; by default, simply scan the projectroot dir. $ projects_list = $ projectroot; # stylesheet to use @ stylesheets = ("/gitweb/static/gitweb.css"); # javascript code for gitweb $ javascript = "gitweb/static/gitweb. js "; # logo to use $ logo ="/gitweb/static/git-logo.png "; # the 'favicons' $ favicon ="/gitweb/static/git-favicon.png "; # git-diff-tree (1) options to use for generated patches # @ diff_opts = ("-M"); @ diff_opts = ();
8.4 configure the default web directory/var/www in apache2ubuntu, and the default cgi directory is/usr/lib/cgi-bin/. after gitweb is installed, gitweb of gitweb is deployed. cgi is automatically placed in this directory. If your cgi path is not the default/usr/lib/cgi-bin/, you need to install gitweb in/usr/lib/cgi-bin. copy cgi to the original configured cgi-bin path, and in the apache configuration file/etc/apache2/apache. add the following content to the end of conf: SetEnv GITWEB_CONFIG/etc/gitweb. conf Options FollowSymlinks ExecCGI Allow from all AllowOverride all Order allow, deny SetHandler cgi-script Www.2cto.com RewriteEngine on RewriteCond % {REQUEST_FILENAME }! -F RewriteCond % {REQUEST_FILENAME }! -D RewriteRule ^. */gitweb. cgi/$0 [L, PT]
8.5 restart apachesudo/etc/init. d/apache2 restart access http: // localhost/cgi-bin/gitweb. cgi: if other new members cannot clone a git repository, the following ERROR occurs: ERROR: gitosis. serve. main: Repository read access denied because the key of the current member is named in gitosis. the members names in conf are inconsistent! For example, the key used is lxq_rsa.pub, and the name used in a group in gitosis. conf is lxq @ ubuntu, you only need to rename lxq_rsa.pub to the lxq@ubuntu.pub and re-push it to the server! By GUMINCONG
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.