Git: Difference between revisions

From KevinWiki
Jump to navigationJump to search
Line 107: Line 107:
   Hostname host.name
   Hostname host.name
   Port 1111
   Port 1111
 
  Host another.host.name
  Host another.host.name
   Hostname another.host.name
   Hostname another.host.name
   Port 2222
   Port 2222
 
  Host host1
  Host host1
   Hostname host.name
   Hostname host.name
  Port 1111
   User git
   User git
   IdentityFile ~/.ssh/git_rsa.pub
   IdentityFile ~/.ssh/git_rsa.pub

Revision as of 14:56, 29 July 2012

Git

Client-side Installation

In the client,

$ apt-get install git-core 
$ git config --global user.name "GivenName Surname" 
$ git config --global user.email user@email.address 

Server-side Installation

In the server,

$ apt-get install git 

Gitolite

Add User to Manage Gitolite

  1. Add user to manage gitolite
$ adduser \
  --system \
  --shell /bin/bash \
  --gecos 'git version control' \
  --group \
  --disabled-password \
  --home /home/git \
  git

Adding system user `git' (UID 108) ...
Adding new group `git' (GID 110) ...
Adding new user `git' (UID 108) with group `git' ...
Creating home directory `/home/git' ...

Create SSH key

$ ssh-keygen -t rsa 

/home/username/.ssh/some_git_rsa [ENTER] [ENTER]

Transfer SSH Keys to Server

$ ssh-copy-id '-p PORT_NUMBER -i /home/user/.ssh/some_git_rsa.pub git_user@host' 

If it doesn't work because the user is the only user who can access the server with his/her ssh key so accessing with git_user doesn't work.

$ scp -P PORT ~/.ssh/some_git_rsa.pub user@host: 

Log in with the user account

$ ssh -p PORT user@host
$ mv some_git_rsa.pub git.pub 

Setup

$ su - git 
$ cd ~ 
$ echo "PATH=$HOME/bin:$PATH" >> ~/.bashrc 
  • don't need these 2 lines
$ mkdir .ssh 
$ cat /home/user/git.pub >> /home/git/.ssh/authorized_keys 
$ exit

Gitolite Installation

$ sudo -i 
$ apt-get install gitolite
[ENTER] -> :q to exit
$ exit

Setup git User

$ su - git
$ gl-setup /home/user/git.pub 
$ vim /etc/ssh/sshd_config 

Add git to the allowed user

AllowUsers user git

Restart ssh

$ service ssh restart 

Test

  • Testing (from user local machine)
$ ssh -p PORT_NUMBER git@host 

Having many keys?

$ ssh -p PORT_NUMBER -i ~/.ssh/user@host1.pub git@host 

For debugging

$ ssh -p PORT_NUMBER -vT git@host 
$ mkdir some-dir 
$ cd some-dir 
$ git clone git@host:gitolite-admin 

Or if you use a specific port,

$ git clone ssh://git@host:PORT_NUMBER/gitolite-admin

Add Git User (through Gitolite)

Adding User

$ cd gitolite-admin/keydir 
$ mkdir user_name 
$ cp ~/.ssh/user@host1.pub .
$ cp ~/.ssh/user@host2.pub .
$ git add user@host1.pub 
$ git commit -a -m "users added: user@host1 and user@host2" 
$ git push

Usage

Host Info Config using SSH_Config

Create ~/.ssh/config file and edit.

Host host.name
  Hostname host.name
  Port 1111

Host another.host.name
  Hostname another.host.name
  Port 2222

Host host1
  Hostname host.name
  Port 1111
  User git
  IdentityFile ~/.ssh/git_rsa.pub

Host user-host2
  Hostname host2.name
  Port 1234
  User user
  IdentityFile ~/.ssh/user@localhost1.pub

Host user-host3
  Hostname host3.com
  Port 1122
  User user
  IdentityFile ~/.ssh/user@localhost1.pub

To use this info,

$ git clone git@host1:repo-name 
# it will use 'git' as a user and access the server 'host.name' using the port nubmer 1111.
$ git clone git@host1:repo-name 
# it will use 'user' as a user and access the server 'host2.name' using the port nubmer 1234.

Push to Specific Host

$ git push git@host1:repo-name master