Skip to content

Commit bf594bf

Browse files
committed
Merge pull request #223 from oldsharp/pull/translate/04-git-server/setting-up-server-original-pull-114
Translate 04-git-server setting-up-server (Originally #114 )
2 parents 1613ce0 + 0bb66dd commit bf594bf

File tree

2 files changed

+31
-30
lines changed

2 files changed

+31
-30
lines changed
Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
[[_setting_up_server]]
2-
=== Setting Up the Server
2+
=== 配置服务器
33

4-
Let's walk through setting up SSH access on the server side.
5-
In this example, you'll use the `authorized_keys` method for authenticating your users.
6-
We also assume you're running a standard Linux distribution like Ubuntu.
7-
First, you create a 'git' user and a `.ssh` directory for that user.
4+
我们来看看如何配置服务器端的 SSH 访问。
5+
本例中,我们将使用 `authorized_keys` 方法来对用户进行认证。
6+
同时我们假设你使用的操作系统是标准的 Linux 发行版,比如 Ubuntu
7+
首先,创建一个操作系统用户 `git`,并为其建立一个 `.ssh` 目录。
88

99
[source,console]
1010
----
@@ -15,9 +15,9 @@ $ mkdir .ssh && chmod 700 .ssh
1515
$ touch .ssh/authorized_keys && chmod 600 .ssh/authorized_keys
1616
----
1717

18-
Next, you need to add some developer SSH public keys to the `authorized_keys` file for the `git` user.
19-
Let's assume you have some trusted public keys and have saved them to temporary files.
20-
Again, the public keys look something like this:
18+
接着,我们需要为系统用户 `git` 的 `authorized_keys` 文件添加一些开发者 SSH 公钥。
19+
假设我们已经获得了若干受信任的公钥,并将它们保存在临时文件中。
20+
与前文类似,这些公钥看起来是这样的:
2121

2222
[source,console]
2323
----
@@ -30,7 +30,7 @@ O7TCUSBdLQlgMVOFq1I2uPWQOkOWQAHukEOmfjy2jctxSDBQ220ymjaNsHT4kgtZg2AYYgPq
3030
dAv8JggJICUvax2T9va5 gsg-keypair
3131
----
3232

33-
You just append them to the `git` user's `authorized_keys` file in its `.ssh` directory:
33+
将这些公钥加入系统用户 `git` 的 `.ssh` 目录下 `authorized_keys` 文件的末尾:
3434

3535
[source,console]
3636
----
@@ -39,7 +39,7 @@ $ cat /tmp/id_rsa.josie.pub >> ~/.ssh/authorized_keys
3939
$ cat /tmp/id_rsa.jessica.pub >> ~/.ssh/authorized_keys
4040
----
4141

42-
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)))
42+
现在我们来为开发者新建一个空仓库。可以借助带 `--bare` 选项的 `git init` 命令来做到这一点,该命令在初始化仓库时不会创建工作目录:(((git commands, init, bare)))
4343

4444
[source,console]
4545
----
@@ -50,14 +50,14 @@ $ git init --bare
5050
Initialized empty Git repository in /opt/git/project.git/
5151
----
5252

53-
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.
54-
Note that someone must shell onto the machine and create a bare repository every time you want to add a project.
55-
Let's use `gitserver` as the hostname of the server on which you've set up your 'git' user and repository.
56-
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):
53+
接着,JohnJosie 或者 Jessica 中的任意一人可以将他们项目的最初版本推送到这个仓库中,他只需将此仓库设置为项目的远程仓库并向其推送分支。
54+
请注意,每添加一个新项目,都需要有人登录服务器取得 shell,并创建一个裸仓库。
55+
我们假定这个设置了 `git` 用户和 Git 仓库的服务器使用 `gitserver` 作为主机名。
56+
同时,假设该服务器运行在内网,并且你已在 DNS 配置中将 `gitserver` 指向此服务器。那么我们可以运行如下命令(假定 `myproject` 是已有项目且其中已包含文件):
5757

5858
[source,console]
5959
----
60-
# on Johns computer
60+
# on John's computer
6161
$ cd myproject
6262
$ git init
6363
$ git add .
@@ -66,7 +66,7 @@ $ git remote add origin git@gitserver:/opt/git/project.git
6666
$ git push origin master
6767
----
6868

69-
At this point, the others can clone it down and push changes back up just as easily:
69+
此时,其他开发者可以克隆此仓库,并推回各自的改动,步骤很简单:
7070

7171
[source,console]
7272
----
@@ -77,14 +77,15 @@ $ git commit -am 'fix for the README file'
7777
$ git push origin master
7878
----
7979

80-
With this method, you can quickly get a read/write Git server up and running for a handful of developers.
80+
通过这种方法,你可以快速搭建一个具有读写权限、面向多个开发者的 Git 服务器。
8181

82-
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.
82+
需要注意的是,目前所有(获得授权的)开发者用户都能以系统用户 `git` 的身份登录服务器从而获得一个普通 shell。
83+
如果你想对此加以限制,则需要修改 `passwd` 文件中(`git` 用户所对应)的 shell 值。
8384

84-
You can easily restrict the 'git' user to only doing Git activities with a limited shell tool called `git-shell` that comes with Git.
85-
If you set this as your 'git' user's login shell, then the 'git' user can't have normal shell access to your server.
86-
To use this, specify `git-shell` instead of bash or csh for your user's login shell.
87-
To do so, you must first add `git-shell` to `/etc/shells` if it's not already there:
85+
借助一个名为 `git-shell` 的受限 shell 工具,你可以方便地将用户 `git` 的活动限制在与 Git 相关的范围内。该工具随 Git 软件包一同提供。
86+
如果将 `git-shell` 设置为用户 `git` 的登录 shell(login shell),那么用户 `git` 便不能获得此服务器的普通 shell 访问权限。
87+
若要使用 `git-shell`,需要用它替换掉 bash csh,使其成为系统用户的登录 shell
88+
为进行上述操作,首先你必须确保 `git-shell` 已存在于 `/etc/shells` 文件中:
8889

8990
[source,console]
9091
----
@@ -93,15 +94,15 @@ $ which git-shell # make sure git-shell is installed on your system.
9394
$ sudo vim /etc/shells # and add the path to git-shell from last command
9495
----
9596

96-
Now you can edit the shell for a user using `chsh <username>`:
97+
现在你可以使用 `chsh <username>` 命令修改任一系统用户的 shell:
9798

9899
[source,console]
99100
----
100101
$ sudo chsh git # and enter the path to git-shell, usually: /usr/bin/git-shell
101102
----
102103

103-
Now, the 'git' user can only use the SSH connection to push and pull Git repositories and can't shell onto the machine.
104-
If you try, you'll see a login rejection like this:
104+
这样,用户 `git` 就只能利用 SSH 连接对 Git 仓库进行推送和拉取操作,而不能登录机器并取得普通 shell
105+
如果试图登录,你会发现尝试被拒绝,像这样:
105106

106107
[source,console]
107108
----
@@ -111,7 +112,7 @@ hint: ~/git-shell-commands should exist and have read and execute access.
111112
Connection to gitserver closed.
112113
----
113114

114-
Now Git network commands will still work just fine but the users won't be able to get a shell.
115-
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.
116-
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.
117-
Run `git help shell` for more information on customizing the shell.(((git commands, help)))
115+
现在,网络相关的 Git 命令依然能够正常工作,但是开发者用户已经无法得到一个普通 shell 了。
116+
正如输出信息所提示的,你也可以在 `git` 用户的家目录下建立一个目录,来对 `git-shell` 命令进行一定程度的自定义。
117+
比如,你可以限制掉某些本应被服务器接受的 Git 命令,或者对刚才的 SSH 拒绝登录信息进行自定义,这样,当有开发者用户以类似方式尝试登录时,便会看到你的信息。
118+
要了解更多有关自定义 shell 的信息,请运行 `git help shell`(((git commands, help)))

status.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"sections/gitweb.asc": 0,
4242
"sections/hosted.asc": 100,
4343
"sections/protocols.asc": 17,
44-
"sections/setting-up-server.asc": 0,
44+
"sections/setting-up-server.asc": 100,
4545
"sections/smart-http.asc": 100
4646
},
4747
"05-distributed-git": {

0 commit comments

Comments
 (0)