converting local git repository to remote git repository within LAN

This is a squeal post for my previous post for local git repository

Reason for this upgrade:

I have 2 different machines only desktop PC and a laptop; I work on both with code being updated on both by me at different times, I want a common code base to start with without limitation of different code base.

Previous solutions:

I tried copying the gitrepo between machines each time. this seems to be not that good idea.

Whats now?

So lets create a remote repository on on machine and connect to repository by both machine as remote users. alteast I can do code push once in a day.

How we go about:

wonderful link by ” vincepii ” at link this will be an extended detailed version, So here we go

1. SSH Server configuration

installation of ssh server.


me@me-desktop:~$ sudo apt-get install openssh-server

configuring ssh server with below content

# Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)
ChallengeResponseAuthentication no

# Change to no to disable tunnelled clear text passwords
PasswordAuthentication no
me@me-desktop:~$ sudo vim /etc/ssh/sshd_config 
me@me-desktop:~$ sudo service ssh restart
ssh stop/waiting
ssh start/running, process 12960

Authorized Keys configuration on server

create new user and group, clean way of doing it.


me@me-desktop:~$ sudo adduser git
Adding user `git' ...
Adding new group `git' (1002) ...
Adding new user `git' (1002) with group `git' ...
Creating home directory `/home/git' ...
Copying files from `/etc/skel' ...
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully
Changing the user information for git
Enter the new value, or press ENTER for the default
    Full Name []: git 
    Room Number []: 
    Work Phone []: 
    Home Phone []: 
    Other []: 
Is the information correct? [Y/n] y

login into git user and create .ssh folder and “authorized_keys” file with correct permissions, this will be used to keep the user key


me@me-desktop:~$ su git
Password: 
git@me-desktop:/home/me$ cd
git@me-desktop:~$ pwd
/home/git
git@me-desktop:~$ vim .ssh
git@me-desktop:~$ mkdir .ssh
git@me-desktop:~$ chmod 700 .ssh
git@me-desktop:~$ touch .ssh/authorized_keys
git@me-desktop:~$ chmod 600 .ssh/authorized_keys 

Creating ssh key on client machines


me@me-desktop:~$ ssh-keygen -t rsa -C "mydesktop"
Generating public/private rsa key pair.
Enter file in which to save the key (/home/me/.ssh/id_rsa): 
Created directory '/home/me/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/me/.ssh/id_rsa.
Your public key has been saved in /home/me/.ssh/id_rsa.pub.
The key fingerprint is:
4a:bd:92:c0:03:5b:b9:c2:53:ad:02:6c:24:7b:39:60 mydesktop
The key's randomart image is:
+--[ RSA 2048]----+
|oE               |
|=o . o           |
|oo= + .          |
|.+ B o .         |
|  * * . S        |
|   + + o .       |
|      + .        |
|       .         |
|                 |
+-----------------+
me@me-desktop:~$ ls ~/.ssh/
id_rsa  id_rsa.pub  known_hosts

Updating the keys in git Server

copy your “id_rsa.pub” from the users to server and follow as below, you can confirm the content of the “authorized_keys” file in server to have contents of the user id_rsa.pub file.


me@me-desktop:~$ sudo bash -c "cat .ssh/id_rsa.pub >> ../git/.ssh/authorized_keys"
[sudo] password for me: 
me@me-desktop:~$ su git
Password: 
git@me-desktop:/home/me$ vim /home/git/.ssh/authorized_keys 
git@me-desktop:/home/me$ exit

configuring the repo for multiusers


me@me-desktop:/gitrepo$ ls -al
total 16
drwxrwxr-x 4 me me 4096 Jun 18 14:19 .
drwxrwxr-x 3 me me 4096 Jun 15 14:12 ..
drwxrwxr-x 7 me me 4096 Jun 15 14:12 project.git
me@me-desktop:/gitrepo$ cd project.git/
me@me-desktop:/gitrepo/project.git$ git config core.sharedRepository
me@me-desktop:/gitrepo/project.git$ git config core.sharedRepository group
me@me-desktop:/gitrepo/project.git$ git config core.sharedRepository
group
me@me-desktop:/gitrepo/project.git$ cd ..

me@me-desktop:/gitrepo$ sudo chmod g+s project.git/
[sudo] password for me: 
me@me-desktop:/gitrepo$ ls -la
total 16
drwxrwxr-x 4 me me 4096 Jun 18 14:19 .
drwxrwxr-x 3 me me 4096 Jun 15 14:12 ..
drwxrwxr-x 7 me me 4096 Jun 15 14:12 project.git
me@me-desktop:/gitrepo$ sudo chmod g+s project.git
[sudo] password for me: 
me@me-desktop:/gitrepo$ ls -la
total 16
drwxrwxr-x 4 me me 4096 Jun 18 14:19 .
drwxrwxr-x 3 me me 4096 Jun 15 14:12 ..
drwxrwxr-x 7 me me 4096 Jun 15 14:12 project.git
me@me-desktop:/gitrepo$ sudo chgrp -R git .
me@me-desktop:/gitrepo$ ls -la
total 16
drwxrwxr-x 4 me git 4096 Jun 18 14:19 .
drwxrwxr-x 3 me me  4096 Jun 15 14:12 ..
drwxrwxr-x 7 me git 4096 Jun 15 14:12 project.git
me@me-desktop:/gitrepo$ sudo chmod -R g+rwX .
me@me-desktop:/gitrepo$ ls -la
total 16
drwxrwxr-x 4 me git 4096 Jun 18 14:19 .
drwxrwxr-x 3 me me  4096 Jun 15 14:12 ..
drwxrwxr-x 7 me git 4096 Jun 15 14:12 project.git
me@me-desktop:/gitrepo$ find . -type d -exec chmod g+s '{}' +
me@me-desktop:/gitrepo$ 

syncing code form remote git server

now clone the code from the git server, important thing to notice we should have a static ip configured on your server machine.


me@me-desktop:~/prj$ git clone ssh://git@192.168.2.3/gitrepo/project.git
Cloning into 'project'...
remote: Counting objects: 436, done.
remote: Compressing objects: 100% (430/430), done.
remote: Total 436 (delta 288), reused 0 (delta 0)
Receiving objects: 100% (436/436), 79.76 KiB, done.
Resolving deltas: 100% (288/288), done.

“git push origin” should be used once we have made the changes and we have a uptodate remote repo.
“git pull” will get the latest code and have the base line always ready.

So hope this will help few who want to verify steps in detail.

Advertisements

About preetammn

engineer trying to figure out the world, people and machines.
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s