総数:45 今日:1 昨日:1

もくじ

sshの準備 client側

公開鍵が既に作成されているかどうか確認する

ある場合は、公開鍵は ~/.ssh というディレクトリにあるはず。

~$ ls -la .ssh

公開鍵がまだ無い場合は作成する

ssh-keygenコマンドで作成する。

~$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/<username>/.ssh/id_rsa):←★このままenterキーを押す 
Created directory '/home/<username>/.ssh'.
Enter passphrase (empty for no passphrase): ←★このままenterキーを押す
Enter same passphrase again: ←★このままenterキーを押す
Your identification has been saved in /home/<username>/.ssh/id_rsa.
Your public key has been saved in /home/<username>/.ssh/id_rsa.pub.
The key fingerprint is:
b6:(・・・省略・・・):07 <username>@<hostname>
The key's randomart image is:
+--[ RSA 2048]----+
|= (・・省略・・) |
|                 |
+-----------------+
~$

作成された鍵ファイルを確認する。

~$ ls -la .ssh
合計 16
drwx------  2 <username> <username> 4096  2月 28 20:59 .
drwxr-xr-x 47 <username> <username> 4096  2月 28 20:58 ..
-rw-------  1 <username> <username> 1679  2月 28 20:59 id_rsa ←★秘密鍵
-rw-r--r--  1 <username> <username>  397  2月 28 20:59 id_rsa.pub ←★公開鍵
~$

自分(client)の公開鍵を Git サーバーの管理者に連絡する。

id_rsa.pubの内容をメールなどでGit サーバーの管理者に連絡する。

sshの準備 sever側

ubuntu15.10 desktop をgitサーバとして使用することにしよう

ubuntu15.10 desktop を virtual box で仮想マシン上にインストールする。

virtual box のインストール

~$ sudo apt-get update
~$ sudo apt-get install virtualbox

ubuntu-15.10-desktop のダウンロード

以下からダウンロードする。
http://ftp.riken.jp/Linux/ubuntu-releases/wily/ubuntu-15.10-desktop-amd64.iso

ubuntu15.10 desktop を virtual box で仮想マシン上にインストールする。

手順は省略。

gituserというユーザを作成しておく

gituserが所属するグループを確認する。

gituser@mother:~$ groups gituser 
gituser : gituser adm cdrom sudo dip plugdev lpadmin sambashare

openssh-serverをインストールしておく。

gituser@mother:~$ sudo apt-get -y install openssh-server

.ssh ディレクトリを作成しておく。

gituser@mother:~$ mkdir .ssh

gitクライアントたちの SSH 公開鍵をそのユーザーの authorized_keys に追加していく

あらかじめホストOSとの共有ディレクトリ /media/sf_share_with_host/ に 公開鍵ファイル を置いておくとする。

gituser@mother:~$ sudo su
[sudo] password for gituser: 
root@mother:/home/gituser# ls -la /media/sf_share_with_host/
合計 12
drwxrwx--- 1 root vboxsf 4096  2月 28 22:11 .
drwxr-xr-x 4 root root   4096  2月 28 22:10 ..
root@mother:/home/gituser# cp -p /media/sf_share_with_host/id_rsa.pub Downloads/
root@mother:/home/gituser# exit
exit
gituser@mother:~$ ls -la Downloads/
gituser@mother:~$ ls -la Downloads/
合計 12
drwxr-xr-x  2 gituser gituser 4096  2月 28 22:15 .
drwxr-xr-x 20 gituser gituser 4096  2月 28 22:10 ..
-rwxrwx---  1 root    vboxsf   397  2月 28 20:59 id_rsa.pub
gituser@mother:~$ sudo chown gituser:gituser Downloads/id_rsa.pub
gituser@mother:~$ ls -la Downloads/
合計 12
drwxr-xr-x  2 gituser gituser 4096  2月 28 22:15 .
drwxr-xr-x 20 gituser gituser 4096  2月 28 22:10 ..
-rwxrwx---  1 gituser gituser  397  2月 28 20:59 id_rsa.pub
gituser@mother:~$

これを authorized_keys に追加していく。

gituser@mother:~$ cat Downloads/id_rsa.pub >> ~/.ssh/authorized_keys
gituser@mother:~$ ls -la .ssh/
合計 12
drwxrwxr-x  2 gituser gituser 4096  2月 28 22:27 .
drwxr-xr-x 20 gituser gituser 4096  2月 28 22:10 ..
-rw-rw-r--  1 gituser gituser  397  2月 28 22:27 authorized_keys
gituser@mother:~$

gitをインストールする。

gituser@mother:~$ sudo apt-get -y install git-core

gitクライアントが使うための空のリポジトリを作成する。

gituser@mother:~$ mkdir project_000.git
gituser@mother:~$ cd project_000.git/
gituser@mother:~/project_000.git$ git --bare init --shared
Initialized empty shared Git repository in /home/gituser/project_000.git/
gituser@mother:~/project_000.git$

gitクライアント側

git initでリポジトリ作成する

$ mkdir -p ~/repositories/my_project/
$ cd ~/repositories/my_project/
$ git init

index.htmlを作成する。

git add.

~/repositories/my_project$ git add.

git commit

~/repositories/my_project$ git commit -v

git remote add origin gituser@192.168.24.59:/home/gituser/project_000.git

~/repositories/my_project$ git remote add origin gituser@192.168.24.59:/home/gituser/project_000.git

git push origin master

~/repositories/my_project$ git push origin master 
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 268 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To gituser@192.168.24.59:/home/gituser/project_000.git
 * [new branch]      master -> master
~/repositories/my_project$

トップ   一覧 単語検索 最終更新   ヘルプ   最終更新のRSS