-
Notifications
You must be signed in to change notification settings - Fork 63
/
Copy pathsetting-up-server.asc
196 lines (173 loc) · 9.05 KB
/
setting-up-server.asc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
[[_setting_up_server]]
//////////////////////////
=== Setting Up the Server
//////////////////////////
=== 서버 설정하기
//////////////////////////
Let's walk through setting up SSH access on the server side.
In this example, you'll use the `authorized_keys` method for authenticating your users.
We also assume you're running a standard Linux distribution like Ubuntu.
//////////////////////////
서버에서 설정하는 일을 살펴보자.
일단 Ubuntu같은 표준 Linux 배포판을 사용한다고 가정한다.
사용자들은 아마도 `authorized_keys` 파일로 인증할 것이다.
[NOTE]
====
//////////////////////////
A good deal of what is described here can be automated by using the `ssh-copy-id` command, rather than manually copying and installing public keys.
//////////////////////////
`ssh-copy-id` 명령을 사용하면 여기에서 설명하는 SSH 공개키를 복사하고 설치하는 내용을 자동화 한 도구이다.
====
//////////////////////////
First, you create a `git` user and a `.ssh` directory for that user.
//////////////////////////
먼저 `git` 계정을 만들고 사용자 홈 디렉토리에 `.ssh` 디렉토리를 만든다:
[source,console]
----
$ sudo adduser git
$ su git
$ cd
$ mkdir .ssh && chmod 700 .ssh
$ touch .ssh/authorized_keys && chmod 600 .ssh/authorized_keys
----
//////////////////////////
Next, you need to add some developer SSH public keys to the `authorized_keys` file for the `git` user.
Let's assume you have some trusted public keys and have saved them to temporary files.
Again, the public keys look something like this:
//////////////////////////
`authorized_keys` 파일에 SSH 공개키를 추가해야 사용자가 접근할 수 있다.
추가하기 전에 이미 알고 있는 사람의 공개키를 받아서 가지고 있다고 가정한다.
공개키가 어떻게 생겼는지 다시 한번 확인하자.
[source,console]
----
$ cat /tmp/id_rsa.john.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCB007n/ww+ouN4gSLKssMxXnBOvf9LGt4L
ojG6rs6hPB09j9R/T17/x4lhJA0F3FR1rP6kYBRsWj2aThGw6HXLm9/5zytK6Ztg3RPKK+4k
Yjh6541NYsnEAZuXz0jTTyAUfrtU3Z5E003C4oxOj6H0rfIF1kKI9MAQLMdpGW1GYEIgS9Ez
Sdfd8AcCIicTDWbqLAcU4UpkaX8KyGlLwsNuuGztobF8m72ALC/nLF6JLtPofwFBlgc+myiv
O7TCUSBdLQlgMVOFq1I2uPWQOkOWQAHukEOmfjy2jctxSDBQ220ymjaNsHT4kgtZg2AYYgPq
dAv8JggJICUvax2T9va5 gsg-keypair
----
//////////////////////////
You just append them to the `git` user's `authorized_keys` file in its `.ssh` directory:
//////////////////////////
`.ssh` 디렉토리에 있는 `authorized_keys` 파일에 추가한다:
[source,console]
----
$ cat /tmp/id_rsa.john.pub >> ~/.ssh/authorized_keys
$ cat /tmp/id_rsa.josie.pub >> ~/.ssh/authorized_keys
$ cat /tmp/id_rsa.jessica.pub >> ~/.ssh/authorized_keys
----
//////////////////////////
Now, you can set up an empty repository for them by running `git init` with the `--bare` option, which initializes the repository without a working directory:(((git commands, init, bare)))
//////////////////////////
`--bare` 옵션을 주고 `git init` 를 실행해서 워킹 디렉토리가 없는 빈 저장소를 하나 만든다.(((git commands, init, bare)))
[source,console]
----
$ cd /srv/git
$ mkdir project.git
$ cd project.git
$ git init --bare
Initialized empty Git repository in /srv/git/project.git/
----
//////////////////////////
Then, John, Josie, or Jessica can push the first version of their project into that repository by adding it as a remote and pushing up a branch.
Note that someone must shell onto the machine and create a bare repository every time you want to add a project.
Let's use `gitserver` as the hostname of the server on which you've set up your `git` user and repository.
If you're running it internally, and you set up DNS for `gitserver` to point to that server, then you can use the commands pretty much as is (assuming that `myproject` is an existing project with files in it):
//////////////////////////
이제 John, Josie, Jessica는 이 저장소를 리모트 저장소로 등록하고 나서 브랜치를 Push 할 수 있다.
프로젝트마다 적어도 한 명은 서버에 접속해서 Bare 저장소를 만들어야 한다.
`git` 계정과 저장소를 만든 서버의 호스트 이름이 `gitserver` 라고 하자.
만약 이 서버가 내부망에 있고 `gitserver` 가 그 서버를 가리키도록 DNS에 설정하면 아래와 같은 명령을 사용할 수 있다(`myproject` 프로젝트가 이미 있다고 가정한다).
[source,console]
----
# on John's computer
$ cd myproject
$ git init
$ git add .
$ git commit -m 'initial commit'
$ git remote add origin git@gitserver:/srv/git/project.git
$ git push origin master
----
//////////////////////////
At this point, the others can clone it down and push changes back up just as easily:
//////////////////////////
이제 이 프로젝트를 Clone 하고 나서 수정하고 Push 할 수 있다.
[source,console]
----
$ git clone git@gitserver:/srv/git/project.git
$ cd project
$ vim README
$ git commit -am 'fix for the README file'
$ git push origin master
----
//////////////////////////
With this method, you can quickly get a read/write Git server up and running for a handful of developers.
//////////////////////////
이렇게 개발자들이 읽고 쓸 수 있는 Git 서버를 쉽게 만들 수 있다.
//////////////////////////
You should note that currently all these users can also log into the server and get a shell as the `git` user.
If you want to restrict that, you will have to change the shell to something else in the `passwd` file.
//////////////////////////
이 개발자들은 서버에 `git` 계정으로 로그인할 수 있다.
이를 막으려면 `passwd` 파일에서 로그인 셸을 바꿔야한다.
//////////////////////////
You can easily restrict the `git` user to only doing Git activities with a limited shell tool called `git-shell` that comes with Git.
If you set this as your `git` user's login shell, then the `git` user can't have normal shell access to your server.
To use this, specify `git-shell` instead of bash or csh for your user's login shell.
To do so, you must first add `git-shell` to `/etc/shells` if it's not already there:
//////////////////////////
단순히 로그인 셸을 `git-shell` 로 바꾸기만 하면 `git` 계정으로는 `git` 만 사용할 수 있다.
이 로그인 셸은 서버의 다른 부분은 건들 수 없도록 돼있다.
`git-shell` 을 사용자의 로그인 셸로 지정해야 한다.
`/etc/shells` 에 `git-shell` 를 추가한다. 아래를 보자.
[source,console]
//////////////////////////
----
$ cat /etc/shells # see if `git-shell` is already in there. If not...
$ which git-shell # make sure git-shell is installed on your system.
$ sudo vim /etc/shells # and add the path to git-shell from last command
----
//////////////////////////
----
$ cat /etc/shells # 이미 `git-shell` 이 등록돼 있는지 확인
$ which git-shell # git-shell 실행파일이 설치돼 있는지 확인
$ sudo vim /etc/shells # 바로 위 명령으로 확인한 git-shell 실행파일의 절대경로를 추가
----
//////////////////////////
Now you can edit the shell for a user using `chsh <username> -s <shell>`:
//////////////////////////
`chsh <계정이름> -s <shell>` 명령어를 이용해서 특정 계정의 셸을 바꿀 수 있다.
[source,console]
//////////////////////////
----
$ sudo chsh git -s $(which git-shell)
----
//////////////////////////
----
$ sudo chsh git # git-shell 경로를 입력, 보통 /usr/bin/git-shell 임
----
//////////////////////////
Now, the `git` user can only use the SSH connection to push and pull Git repositories and can't shell onto the machine.
If you try, you'll see a login rejection like this:
//////////////////////////
이제 _git_ 계정으로 Push 와 Pull 할 수 있지만 서버의 셸은 가질 수 없다.
로그인하려고 하면 아래와 같이 로그인 불가능 메시지만 보게 될 것이다.
[source,console]
----
$ ssh git@gitserver
fatal: Interactive git shell is not enabled.
hint: ~/git-shell-commands should exist and have read and execute access.
Connection to gitserver closed.
----
//////////////////////////
Now Git network commands will still work just fine but the users won't be able to get a shell.
As the output states, you can also set up a directory in the `git` user's home directory that customizes the `git-shell` command a bit.
For instance, you can restrict the Git commands that the server will accept or you can customize the message that users see if they try to SSH in like that.
Run `git help shell` for more information on customizing the shell.(((git commands, help)))
//////////////////////////
이제 Git은 제대로 동작하면서 개발자들이 셸을 얻지 못하게 되었다.
위의 출력에서 볼 수 있듯이 `git` 계정의 홈 디렉토리에 `git-shell-commands` 디렉토리를 만들어 `git-shell` 의 동작을 조금 바꿀 수 있다.
예를 들면 서버에서 사용할 수 있는 Git 명령어를 제한할 수 있다. 또 명령어를 실행했을 때 나오는 메시지도 변경 할 수 있다.
`git help shell` 명령어를 실행하면 Git 셸을 꾸미는 데에 필요한 정보를 얻을 수 있다. (((git commands, help)))