Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions book/04-git-server/sections/generating-ssh-key.asc
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[[_generate_ssh_key]]
=== Generating Your SSH Public Key
=== 生成你的SSH公钥
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SSH 前后两端加空格,后面所有中文句子中出现英文或数字的地方也同样处理。


(((SSH keys)))
That being said, many Git servers authenticate using SSH public keys.
In order to provide a public key, each user in your system must generate one if they don't already have one.
This process is similar across all operating systems.
First, you should check to make sure you don't already have a key.
By default, a user's SSH keys are stored in that user's `~/.ssh` directory.
You can easily check to see if you have a key already by going to that directory and listing the contents:
如人们所说的,许多Git服务器使用SSH公钥来进行认证。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如人们所说,
去掉吧

为了向Git服务器提供一个SSH公钥,每个系统内的用户在没有SSH公钥的情况下必须自行生成。
这个操作在所有的操作系统上都是相似的。
首先,你得确认你是否已经拥有了一个密钥。
一般情况下,用户的SSH公钥储存在 `~/.ssh` 目录内。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

默认情况下,用户的 SSH 密钥存储在其 ~/.ssh 目录下。

你可以通过下面的操作来快速地确认密钥是否已经存在
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你可以简单地通过进入那个文件夹并列出其中的内容来检查你是否已经有了一个密钥:


[source,console]
----
Expand All @@ -17,9 +17,9 @@ authorized_keys2 id_dsa known_hosts
config id_dsa.pub
----

You're looking for a pair of files named something like `id_dsa` or `id_rsa` and a matching file with a `.pub` extension.
The `.pub` file is your public key, and the other file is your private key.
If you don't have these files (or you don't even have a `.ssh` directory), you can create them by running a program called `ssh-keygen`, which is provided with the SSH package on Linux/Mac systems and comes with the MSysGit package on Windows:
你将看见一对名字类似 `id_dsa`(或 `id_rsa`)与其对应的带有 `.pub` 扩展名的密钥。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可不可以这样:

你所寻找的一对文件其中一个名字类似 id_dsaid_rsa,与其对应的另一个则带有 .pub 扩展名。

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你所寻找的一对文件其中一个名字类似……

带有 `.pub` 扩展名的文件是你的公钥,而另一个则是私钥。
如果你找不到这些文件(或者你根本没有 `.ssh` 目录),你可以通过运行Linux/Mac的SSH软件包中的 `ssh-keygen` 程序来创建密钥,在Windows上,这个程序包含于MSysGit软件包中。

[source,console]
----
Expand All @@ -35,11 +35,11 @@ The key fingerprint is:
d0:82:24:8e:d7:f1:bb:9b:33:53:96:93:49:da:9b:e3 schacon@mylaptop.local
----

First it confirms where you want to save the key (`.ssh/id_rsa`), and then it asks twice for a passphrase, which you can leave empty if you don't want to type a password when you use the key.
首先它会确认密钥的存储位置(默认是 `.ssh/id_rsa`),然后它将让你输入两次密钥口令,如果你不想在使用密钥时使用口令,直接留空即可。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

首先它会确认你想把密钥存储在什么地方(.ssh/id_rsa),之后它将要求你两次输入一个口令,如果你不想在使用密钥时输入一个口令,你可以将其置空。


Now, each user that does this has to send their public key to you or whoever is administrating the Git server (assuming you're using an SSH server setup that requires public keys).
All they have to do is copy the contents of the `.pub` file and e-mail it.
The public keys look something like this:
现在,每个完成了上述操作的用户必须将他们的公钥提交给你或任何管理Git服务器的人(假设你正在使用一个需要公钥来设置SSH服务器)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

现在,每个进行上述操作的用户需要将他们的公钥发送给你或者其他管理该 Git 服务器的人(假设你正在使用一个需要公钥的 SSH 服务器设置)。

现在他们需要做的就是将 `.pub` 文件中的内容复制并通过邮件发出。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

他们只需要将其内容复制并且通过电子邮件发送出去就可以了。

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

他们只需将 .pub 文件的内容通过电子邮件发送出去即可

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

他们只需将.pub为扩展名的文件内容通过电子邮件发出去即可。

公钥看起来是这样的:

[source,console]
----
Expand All @@ -52,4 +52,4 @@ mZ+AW4OZPnTPI89ZPmVMLuayrD2cE86Z/il8b+gw3r3+1nKatmIkjn2so1d01QraTlMqVSsbx
NrRFi9wrf+M7Q== schacon@mylaptop.local
----

For a more in-depth tutorial on creating an SSH key on multiple operating systems, see the GitHub guide on SSH keys at https://help.github.com/articles/generating-ssh-keys[].
想要更深入地了解在多种操作系统中生成SSH密钥的方法,请参阅Github的SSH密钥教程:https://help.github.com/articles/generating-ssh-keys[].
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

“请参阅 GitHub 上关于 SSH 密钥的教程。”

56 changes: 28 additions & 28 deletions book/04-git-server/sections/setting-up-server.asc
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[[_setting_up_server]]
=== Setting Up the Server
=== 安装并设置服务器
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

设置服务器,我认为这里没有“安装”的意思,只是设置 SSH 的访问而已。

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同意用设置服务器,这里谈不上安装,不过配置这个词也可以,但是需要有上下文才可以理解。


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.
First, you create a 'git' user and a `.ssh` directory for that user.
我们来看看如何在服务器端设置SSH的访问。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这篇也是,按照 TRANSLATION_NOTES 中的方式处理:

嵌入中文中的英文两端添加空格;如果英文前、后是标点,则不需再添加空格。数字一般也按照英文的方式进行处理。

在这个例子中,你将会使用 `authorized_keys` 来对你的用户进行认证。
当然,我们假设你正在运行的是Ubuntu之类的标准Linux发行版,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我们也假设你正在运行一个 Ubuntu 之类的标准 Linux 发行版。

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我们也假设你正在使用一个Ubuntu之类的标准Linux发行版。

首先,创建一个 `git` 用户并在那个用户的用户文件夹下创建 `.ssh` 目录。

[source,console]
----
Expand All @@ -15,9 +15,9 @@ $ 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:
接下来,你需要将一些开发者的SSH公钥添加到 `git` 用户的 `authorized_keys` 文件中。
我们假设你已经将一些受信任的公钥保存到了一个临时目录中。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我们假设你已经获得了一些受信任的公钥,并将它们保存到了临时文件中。

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里我觉得有待商榷,Ubuntu默认在/tmp文件夹下处理公钥。如果这样翻译是否更为稳妥:我们假设你已经获得了一些受信任的公钥,并将这些公钥保存到了一个/tmp目录中。

同样地,这些公钥看起来是这样的:

[source,console]
----
Expand All @@ -30,7 +30,7 @@ O7TCUSBdLQlgMVOFq1I2uPWQOkOWQAHukEOmfjy2jctxSDBQ220ymjaNsHT4kgtZg2AYYgPq
dAv8JggJICUvax2T9va5 gsg-keypair
----

You just append them to the `git` user's `authorized_keys` file in its `.ssh` directory:
将公钥添加到 `git` 用户的 `authorized_keys` 文件(在 `ssh` 目录)中:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你只需要将它们追加到 git 用户 .ssh 目录中的 authorized_keys 文件下。

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你只需要将他们追加到git用户.ssh目录中的authorized_keys文件里。


[source,console]
----
Expand All @@ -39,7 +39,7 @@ $ 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)))
现在,你可以通过 `git init` 为他们创建一个空仓库,使用 `--bare` 参数可以在没有工作目录的时候初始化仓库:(((git commands, init, bare)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

个人意见:

现在,你可以通过使用 --bare 选项运行 git init 命令初始化一个没有工作目录的仓库,来为他们创建一个空仓库。

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

现在,你可以通过运行带有 --bare 选项的 git init 命令为他们创建一个空仓库,这样你就能在没有工作目录的情况下初始化仓库


[source,console]
----
Expand All @@ -50,10 +50,10 @@ $ git init --bare
Initialized empty Git repository in /opt/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能够通过将这个仓库设置为remote并创建一个新branch来将他们项目的最初版本push到这个仓库中。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我看了其他几个人的翻译,remotebranchpush都直接翻译了

请注意,每次需要添加一个新项目的时候,用户必须要通过shell连接服务器并创建一个无工作目录的仓库。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

请注意,如果要添加一个新项目,必须要有人通过 shell 连接到服务器并创建一个裸仓库。

使用 `gitserver` 作为你设置了 `git` 用户并创建了仓库的服务器的主机名。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

现在让我们使用 gitserver 作为你设置了 git 用户和仓库的服务器的主机名。

如果你正在内网运行这个服务器并在DNS中将 `gitserver` 指向了这个服务器,那么你就可以像这样使用如下命令(假设 `my_project` 已经存在并且其中有文件包含):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my_project 的中间没有下划线。


[source,console]
----
Expand All @@ -66,7 +66,7 @@ $ git remote add origin git@gitserver:/opt/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回来:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上,Git 相关操作应该是要翻译的


[source,console]
----
Expand All @@ -77,14 +77,14 @@ $ 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 服务器并让他为一群开发者服务。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

让他为一群开发者服务=》让它为一群开发者服务


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` 文件中稍作其他改动。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你需要注意的是,目前这些用户也可以使用这个 git 用户登录进服务器并且获得一个 shell。如果你想对此加以限制,你还需要修改 passwd 文件中的 shell。


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 一同安装的名为 `git-shell` 的受限的 shell 来限制 'git' 用户以使其只能进行 Git 活动。
如果你将此设为 `git` 用户的登陆shell,那么该用户便不能通过有一般的shell访问服务器。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果你将其设置为 git 用户的登录 shell,那么该用户便不能获得你机器正常的 shell 访问。

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

……正常的 shell 访问权限

要使用 `git-shell`,请指定 `git-shell` 为用户的登陆shell,而不是 bash、csh等一般 shell
要进行此操作,如果 `/etc/shells` 中不存在 `git-shell`,你必须将 `git-shell` 添加到其中。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

句号改成冒号。


[source,console]
----
Expand All @@ -93,15 +93,15 @@ $ 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
----

Now you can edit the shell for a user using `chsh <username>`:
现在,你可以编辑一个使用 `chsh <username>` 的用户shell:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

现在,你可以使用 chsh <username> 命令改变一个用户的 shell:


[source,console]
----
$ sudo chsh git # and enter the path to git-shell, usually: /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` 只能使用 SSH 连接对 Git 仓库进行 push/pull 操作,而不能通过 shell 控制机器。
试一试,你会发现如下的登陆拒绝信息:

[source,console]
----
Expand All @@ -111,7 +111,7 @@ 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 的网络命令仍然正常的工作但用户不能通过 shell 操作机器。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

现在 Git 的网络命令依然能够正常工作,但是用户不能得到一个 shell。

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

此处的 shell 应该指上文普通的 shell 吧,在前面加个 普通的 是不是更好?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@IceNature 没错。不过这里我觉得比较纠结的地方是,此处的 context 所描述的 git-shell,本身可能并不能称为一个 shell,从这个角度讲倒是无所谓,因为在技术圈中绝大多数情况下说到 shell,就是对机器有一定的控制能力的(包括攻防中的所谓 Web Shell 之类)。无法获取 shell,本身的意思就是不能以这种方式进行远程操作。

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@secondwtq 这个地方我认为就是指普通的 shell 而不是 git-shell,原因是这句话指代的是通过 ssh 连上后可以执行 Git 的命令,而不是作为一个普通的 shell 执行用户想要的各种命令。

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@secondwtq 说的很有道理,但是我觉得加上可以消除歧义,毕竟有读者是新人

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@secondwtq @networm 我基本同意你们的说法,毕竟能够阅读git pro 书籍的并不全都是专业人员。

如同输出所显示的,你同样可以建立 `git` 用户的用户目录以稍稍自定义 `git-shell` 命令。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如同输出中所说,你也可以在 git 用户的用户目录下建立一个文件夹对 git-shell 命令进行一定的自定义。

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如同输出中所说,你可以在git 用户的用户目录下建立一个文件夹来对git-shell命令进行一定程度上的自定义。

举个例子,你可以重定向 Git 的命令从而使服务器接受自定义命令,或者,你可以更改用户像上文那样登陆 SSH 时的提示信息。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

比如,你可以限制服务器可以接受的 Git 命令,或者自定义用户以类似方式尝试 SSH 登录时所看到的信息。

要了解更多有关自定义shell的信息,请运行 `git help shell`(((git commands, help)))