11
9

More than 5 years have passed since last update.

awsでgitサーバー構築

Last updated at Posted at 2015-07-25

authorized_keys方式でユーザーの認証

サーバーへアクセス

# localのssh暗号機を送っておく
[local@instance ~]$ scp -i xxx.pem ~/.ssh/id_rsa.pub ec2-user@xxx.com:/tmp/id_rsa.xxx.pub
# サーバーへアクセス
[local@instance ~]$ ssh -i xxx.pem ec2-user@xxx.com

gitユーザー作成

# rootユーザーに切り替え
[ec2-user@instance ~]$ sudo su -
# ユーザー作成
[root@instance ~]$ adduser git
# パスワード設定
[root@instance ~]$ passwd git
# ユーザgitにsudoを許可する。(任意)
[root@instance ~]$ vi /etc/sudoers
(下記を追記)
git    ALL=(ALL)       ALL

空のリポジトリを作成

[root@instance ~]$ su git
[git@instance root]$ cd ~
[git@instance ~]$ mkdir project.git
[git@instance ~]$ cd project.git
[git@instance project.git]$ git --bare init

localのSSH公開鍵をgitサーバーのauthorized_keysに追加

# .sshディレクトリ作成
[git@instance ~]$ mkdir -p ~/.ssh
# SSH公開鍵をauthorized_keysに追加
[git@instance ~]$ cat /tmp/id_rsa.xxx.pub >> ~/.ssh/authorized_keys

.sshの権限設定

[git@instance ~]$ chmod 600 ~/.ssh/authorized_keys
[git@instance ~]$ chmod 700 ~/.ssh

localからpush, pullしてみる

1回目のユーザーの場合

[local@instance ~]$ mkdir project
[local@instance ~]$ cd project
[local@instance project]$ git init
[local@instance project]$ echo initial commit >> README.md
[local@instance project]$ git add .
[local@instance project]$ git commit -m "initial commit"
[local@instance project]$ git remote add origin git@xxx.com:/home/git/project.git
[local@instance project]$ git push origin master
[local@instance project]$ git pull origin master

2回目以降のユーザーの場合

[local@instance ~]$ git clone git@gitserver:/home/git/project.git
[local@instance ~]$ cd project
[local@instance project]$ echo second commit >> README.md
[local@instance project]$ git commit -am 'second commit'
[local@instance project]$ git push origin master
[local@instance project]$ git pull origin master

参考サイト
https://git-scm.com/book/ja/v1/Git-%E3%82%B5%E3%83%BC%E3%83%90%E3%83%BC-%E3%82%B5%E3%83%BC%E3%83%90%E3%83%BC%E3%81%AE%E3%82%BB%E3%83%83%E3%83%88%E3%82%A2%E3%83%83%E3%83%97

11
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
9