1 |
r0bertz 07/10/04 19:10:16 |
2 |
|
3 |
Modified: metadoc.xml |
4 |
Added: keychain-guide.xml |
5 |
Log: |
6 |
added keychain-guide.xml |
7 |
|
8 |
Revision Changes Path |
9 |
1.12 xml/htdocs/doc/zh_cn/metadoc.xml |
10 |
|
11 |
file : http://sources.gentoo.org/viewcvs.py/gentoo/xml/htdocs/doc/zh_cn/metadoc.xml?rev=1.12&view=markup |
12 |
plain: http://sources.gentoo.org/viewcvs.py/gentoo/xml/htdocs/doc/zh_cn/metadoc.xml?rev=1.12&content-type=text/plain |
13 |
diff : http://sources.gentoo.org/viewcvs.py/gentoo/xml/htdocs/doc/zh_cn/metadoc.xml?r1=1.11&r2=1.12 |
14 |
|
15 |
Index: metadoc.xml |
16 |
=================================================================== |
17 |
RCS file: /var/cvsroot/gentoo/xml/htdocs/doc/zh_cn/metadoc.xml,v |
18 |
retrieving revision 1.11 |
19 |
retrieving revision 1.12 |
20 |
diff -u -r1.11 -r1.12 |
21 |
--- metadoc.xml 3 Oct 2007 17:50:18 -0000 1.11 |
22 |
+++ metadoc.xml 4 Oct 2007 19:10:15 -0000 1.12 |
23 |
@@ -1,6 +1,6 @@ |
24 |
<?xml version="1.0" encoding="UTF-8"?> |
25 |
<!DOCTYPE metadoc SYSTEM "/dtd/metadoc.dtd"> |
26 |
-<!-- $Header: /var/cvsroot/gentoo/xml/htdocs/doc/zh_cn/metadoc.xml,v 1.11 2007/10/03 17:50:18 r0bertz Exp $ --> |
27 |
+<!-- $Header: /var/cvsroot/gentoo/xml/htdocs/doc/zh_cn/metadoc.xml,v 1.12 2007/10/04 19:10:15 r0bertz Exp $ --> |
28 |
<!-- English CVS version: 1.192 --> |
29 |
|
30 |
<metadoc lang="zh_cn" parent="/doc/en/metadoc.xml"> |
31 |
@@ -338,7 +338,7 @@ |
32 |
<file id="security-coordination">/security/en/coordinator_guide.xml</file> |
33 |
<file id="security-recruitment">/security/en/padawans.xml</file> |
34 |
<file id="security-bugs">/security/en/bug-searching.xml</file> |
35 |
- <file id="keychain-guide">/doc/en/keychain-guide.xml</file> |
36 |
+ <file id="keychain-guide">/doc/zh_cn/keychain-guide.xml</file> |
37 |
<file id="metadoc-guide">/proj/en/gdp/doc/metadoc-guide.xml</file> |
38 |
<file id="hpc-howto">/doc/en/hpc-howto.xml</file> |
39 |
<file id="gnap-userguide">/proj/en/base/embedded/gnap-userguide.xml</file> |
40 |
|
41 |
|
42 |
|
43 |
1.1 xml/htdocs/doc/zh_cn/keychain-guide.xml |
44 |
|
45 |
file : http://sources.gentoo.org/viewcvs.py/gentoo/xml/htdocs/doc/zh_cn/keychain-guide.xml?rev=1.1&view=markup |
46 |
plain: http://sources.gentoo.org/viewcvs.py/gentoo/xml/htdocs/doc/zh_cn/keychain-guide.xml?rev=1.1&content-type=text/plain |
47 |
|
48 |
Index: keychain-guide.xml |
49 |
=================================================================== |
50 |
<?xml version='1.0' encoding="utf-8"?> |
51 |
<!DOCTYPE guide SYSTEM "/dtd/guide.dtd"> |
52 |
<!-- $Header: /var/cvsroot/gentoo/xml/htdocs/doc/zh_cn/keychain-guide.xml,v 1.1 2007/10/04 19:10:15 r0bertz Exp $ --> |
53 |
<!-- English CVS version: 1.4 --> |
54 |
|
55 |
<guide link="/doc/zh_cn/keychain-guide.xml" lang="zh_cn"> |
56 |
<title>Gentoo Linux Keychain指南</title> |
57 |
|
58 |
<author title="作者"> |
59 |
<mail link="eric.brown@×××××××.net">Eric Brown</mail> |
60 |
</author> |
61 |
<author title="编者"> |
62 |
<mail link="vanquirius@g.o">Marcelo Góes</mail> |
63 |
</author> |
64 |
<author title="译者"> |
65 |
<mail link="bookstack@×××××.com">Kun Xi</mail> |
66 |
</author> |
67 |
|
68 |
<abstract> |
69 |
本文档描述了如何通过keychain程序来使用ssh秘钥。我们假设读者有公钥加密的基础知识。 |
70 |
</abstract> |
71 |
|
72 |
<!-- The content of this document is licensed under the CC-BY-SA license --> |
73 |
<!-- See http://creativecommons.org/licenses/by-sa/2.5 --> |
74 |
<license/> |
75 |
|
76 |
<version>1.3</version> |
77 |
<date>2007-04-29</date> |
78 |
|
79 |
<chapter> |
80 |
<title>背景</title> |
81 |
<section> |
82 |
<title>手边的难题</title> |
83 |
<body> |
84 |
|
85 |
<p> |
86 |
您终于让所有那些可爱的Gentoo机器都运行sshd了,但是每次登录都需要输入密码却有点不方便,对吧?或者您有一个脚本或cron任务需要一个更加方便快捷的方式进行ssh连接。不管怎样,我们有一个方案可以解决这个难题,它基于公钥认证。 |
87 |
</p> |
88 |
|
89 |
</body> |
90 |
</section> |
91 |
<section> |
92 |
<title>公钥认证是怎么工作的?</title> |
93 |
<body> |
94 |
|
95 |
<p> |
96 |
假设我们有一个客户需要连接到服务器的sshd。该客户首先产生一组公钥/私钥对,然后把公钥提交给服务器。此后,每当该客户试图连接的时候,服务器就用公钥加密一个随机数,发给客户。只有相应的私钥持有者(该客户)才能解密,和您猜想的一样,正确的回复意味着成功的认证。 |
97 |
</p> |
98 |
|
99 |
</body> |
100 |
</section> |
101 |
</chapter> |
102 |
<chapter> |
103 |
<title>如何使用公钥认证</title> |
104 |
<section> |
105 |
<title>生成您的公钥/私钥对</title> |
106 |
<body> |
107 |
|
108 |
<p> |
109 |
第一步是生成您的公钥/私钥对。我们可以运行<c>ssh-keygen</c>,命令如下: |
110 |
</p> |
111 |
|
112 |
<pre caption="生成公钥/私钥对"> |
113 |
$ <i>ssh-keygen -t dsa</i> |
114 |
<comment>(接受默认值,请确保输入一个强密码)</comment> |
115 |
</pre> |
116 |
|
117 |
<warn> |
118 |
请确保输入一个强密码,尤其是用于root登录的私钥! |
119 |
</warn> |
120 |
|
121 |
<p> |
122 |
您现在有一个私钥<path>~/.ssh/id_dsa</path>以及公钥<path>~/.ssh/id_dsa.pub</path>。我们现在可以复制公钥到远程的主机上。 |
123 |
</p> |
124 |
|
125 |
</body> |
126 |
</section> |
127 |
<section> |
128 |
<title>准备服务器</title> |
129 |
<body> |
130 |
|
131 |
<p> |
132 |
我们复制<path>~/.ssh/id_dsa.pub</path>到运行sshd的服务器。我们要将它加入到该用户在服务器上相应帐号的<path>~/.ssh/authorized_keys</path>中。以下是一个例子,我们假设您已经可以用ssh访问服务器。 |
133 |
</p> |
134 |
|
135 |
<pre caption="复制公钥到服务器"> |
136 |
$ <i>scp ~/.ssh/id_dsa.pub server_user@server:~/myhost.pub</i> |
137 |
$ <i>ssh server_user@server "cat ~/myhost.pub >> ~/.ssh/authorized_keys"</i> |
138 |
$ <i>ssh server_user@server "cat ~/.ssh/authorized_keys"</i> |
139 |
</pre> |
140 |
|
141 |
<p> |
142 |
最后一行的输出显示了<path>~/.ssh/authorized_keys</path>文件的内容。请确保它看起来是正确的 |
143 |
</p> |
144 |
|
145 |
</body> |
146 |
</section> |
147 |
<section> |
148 |
<title>测试设置</title> |
149 |
<body> |
150 |
|
151 |
<p> |
152 |
理论上,如果一切工作正常,并且服务器端的ssh守护进程允许的话,无需密码,我们就可以通过ssh访问服务器。在客户端,我们还是需要用上面提到的密码来解密私钥,但是这不同于服务器端的用户密码,请勿混淆。 |
153 |
</p> |
154 |
|
155 |
<pre caption="测试密钥"> |
156 |
$ <i>ssh server_user@server</i> |
157 |
</pre> |
158 |
|
159 |
<p> |
160 |
幸运的话,它会提示您输入id_dsa的密码,您就可以通过ssh,用server_user帐户来访问服务器了。否则,用server_user登录服务器,确保<path>~/.ssh/authorized_keys</path>的每个条目是独立的一行。您也许还需要检查sshd的设置以确保它优先使用公共密钥认证。 |
161 |
|
162 |
</p> |
163 |
|
164 |
<p> |
165 |
此时,您也许会想,“这有什么用呢?用一个密码替换另一个密码?”放轻松,下一节我们会向您展示如何用这个技术来节约您宝贵的时间。 |
166 |
</p> |
167 |
|
168 |
</body> |
169 |
</section> |
170 |
</chapter> |
171 |
<chapter> |
172 |
<title>让公钥认证更加方便</title> |
173 |
<section> |
174 |
<title>使用ssh-agent密钥管理的典型案例</title> |
175 |
<body> |
176 |
|
177 |
<p> |
178 |
如果您跟随我们的脚步,您也许会想,如果用某种方法解密我们的私钥一次,然后无需密码,就可以自由的使用ssh,那该多好啊。好运气属于您,这正是<c>ssh-agent</c>所要做的。 |
179 |
</p> |
180 |
|
181 |
<p> |
182 |
应用程序<c>ssh-agent</c>通常在您开始X会话或者加载shell启动脚本时启动,比如<path>~/.bash_profile</path>。它先创建一个unix套接字,然后注册相应的环境变量,随后的所有应用程序就可以通过连接到这个套接字来使用这项服务。很明显,如果您想在此后的X应用程序里使用解密的私钥的话。您应该在X会话的父进程里启动它。 |
183 |
</p> |
184 |
|
185 |
<pre caption="准备ssh-agent"> |
186 |
$ <i>ssh-agent</i> |
187 |
</pre> |
188 |
|
189 |
<note> |
190 |
ssh-agent会一直持有解密的私钥直到您杀掉ssh-agent进程。如果您希望为私钥设定一个生命周期,您可以用-t选项,详情请参考<c>man |
191 |
ssh-agent</c>。 |
192 |
</note> |
193 |
|
194 |
<p> |
195 |
在您运行ssh-agent时,它会告诉您运行的ssh-agent的PID,并且设置一些环境变量,如<c>SSH_AUTH_SOCK</c>和<c>SSH_AGENT_PID</c>。它还应该自动把<path>~/.ssh/id_dsa</path>加入收藏,并询问相应的密码。如果您希望让运行的ssh-agent管理其他私钥,您可以运行<c>ssh-agent</c>如下: |
196 |
</p> |
197 |
|
198 |
<pre caption="加入更多的私钥到ssh-agent"> |
199 |
$ <i>ssh-add somekeyfile</i> |
200 |
</pre> |
201 |
|
202 |
<p> |
203 |
现在到了表演魔术的时候了。既然您已经准备好了解密的私钥,您应该可以无需密码登录服务器。 |
204 |
</p> |
205 |
|
206 |
<pre caption="无需密码的ssh"> |
207 |
$ <i>ssh server</i> |
208 |
</pre> |
209 |
|
210 |
<p> |
211 |
如果我们知道如何在必要的时候关闭ssh-agent就更好了,不是吗? |
212 |
</p> |
213 |
|
214 |
<pre caption="关闭ssh-agent"> |
215 |
$ <i>ssh-agent -k</i> |
216 |
</pre> |
217 |
|
218 |
<note> |
219 |
如果您无法正常使用ssh-agent,它可能已经正在运行,你可以像强制退出其他进程一样,<c>killall ssh-agent</c>。 |
220 |
</note> |
221 |
|
222 |
<p> |
223 |
如果您希望更多的便利,请前进至下节关于keychain的使用。如果您打算这么作的话,请确保在上例中所有的ssh-agent都被杀掉。 |
224 |
</p> |
225 |
|
226 |
</body> |
227 |
</section> |
228 |
<section> |
229 |
<title>从ssh-agent中榨取最后一滴便利</title> |
230 |
<body> |
231 |
|
232 |
<p> |
233 |
keychain可以允许您在登录过程中重用ssh-agent,并且可选地在每次用户登录后提示输入密码。在我们继续之前,然我们先emerge它。 |
234 |
</p> |
235 |
|
236 |
<pre caption="安装keychain"> |
237 |
# <i>emerge keychain</i> |
238 |
</pre> |
239 |
|
240 |
<p> |
241 |
如果成功的话,我们就可以自由的使用keychain。在您的<path>~/.bash_profile</path>中启动它: |
242 |
</p> |
243 |
|
244 |
<pre caption="在.bash_profile里启用keychain"> |
245 |
keychain ~/.ssh/id_dsa |
246 |
. ~/.keychain/$HOSTNAME-sh |
247 |
</pre> |
248 |
|
249 |
<note> |
250 |
您可以用命令行加入更多的私钥。同时,如果您希望在开启一个新的shell的时候提示输入密码,您可以加入--clear |
251 |
选项。 |
252 |
</note> |
253 |
|
254 |
<note> |
255 |
如果您不使用bash,请查看<c>man keychain</c> <b>EXAMPLES</b>一节关于使用其他shell的例子。关键在于每次您使用shell的时候都必须运行上述命令。 |
256 |
</note> |
257 |
|
258 |
<p> |
259 |
让我们测试一下。首先确保杀掉上节中所有ssh-agent的进程,开启一个新的shell,通常您可以重新登录或者开启一个新的控制台。它会在命令行里提醒您输入每个私钥的密码。此后所有的shell都可以重用ssh-agent,使得您可以不断的无密码登录ssh。 |
260 |
</p> |
261 |
|
262 |
</body> |
263 |
</section> |
264 |
<section> |
265 |
<title>在KDE里使用keychain</title> |
266 |
<body> |
267 |
|
268 |
<p> |
269 |
如果您是KDE用户,除了使用<path>~/.bash_profile</path>,您也可以让KDE为您管理 |
270 |
ssh-agent。您要做的就是编辑 |
271 |
<path>/usr/kde/${KDE_VERSION}/env/agent-startup.sh</path>,它在启动时被读取;以及<path>/usr/kde/${KDE_VERSION}/shutdown/agent-shutdown.sh</path>它在KDE退出是运行,${KDE_VERSION}代表了您安装的KDE版本的头两位数字,比如您使用的是KDE 3.5.1,${KDE_VERSION}就是3.5。以下是如何编辑这些文件: |
272 |
</p> |
273 |
|
274 |
<pre caption="编辑/usr/kde/3.5/env/agent-startup.sh"> |
275 |
if [ -x /usr/bin/ssh-agent ]; then |
276 |
eval "$(/usr/bin/ssh-agent -s)" |
277 |
fi |
278 |
</pre> |
279 |
|
280 |
<pre caption="编辑/usr/kde/3.5/shutdown/agent-shutdown.sh"> |
281 |
if [ -n "${SSH_AGENT_PID}" ]; then |
282 |
eval "$(ssh-agent -k)" |
283 |
fi |
284 |
</pre> |
285 |
|
286 |
<p> |
287 |
现在您所要做的就是启动任意一个控制台,比如Konsole,加载所要的私钥。比如: |
288 |
</p> |
289 |
|
290 |
<pre caption="加载ssh私钥"> |
291 |
keychain ~/.ssh/id_dsa |
292 |
<comment>(输入您的私钥密码)</comment> |
293 |
</pre> |
294 |
|
295 |
<p> |
296 |
您的私钥会一直保留,直到您结束KDE会话或者手动杀掉ssh-agent |
297 |
</p> |
298 |
|
299 |
</body> |
300 |
</section> |
301 |
</chapter> |
302 |
|
303 |
<chapter> |
304 |
<title>结论</title> |
305 |
<section> |
306 |
<title>安全的考量</title> |
307 |
<body> |
308 |
|
309 |
<p> |
310 |
当然,使用ssh-agent会使您的系统有少许的不安全。如果当您在洗手间的时候,其他的用户使用您的shell,他不需密码就可以登录到所有您的服务器。这对于您所连接的服务器是一个隐患,您应该垂询相关的安全策略。如果您使用它,请确保您的会话的安全。 |
311 |
</p> |
312 |
|
313 |
</body> |
314 |
</section> |
315 |
<section> |
316 |
<title>排错</title> |
317 |
<body> |
318 |
|
319 |
<p> |
320 |
大部分情况应该工作正常,但是如果您碰到问题,您肯定希望得到一些有用的帮助。 |
321 |
</p> |
322 |
|
323 |
<ul> |
324 |
<li> |
325 |
如果您不用ssh-agent也无法连接,考虑使用ssh时加入-vvv选项,看看到底发生了什么。有时服务器没有配置使用公共密钥认证,有时它被配置为本地密码无论如何总是需要的!如果是上述情况,您可以用ssh的-o选项,或者更改服务器的sshd_config。 |
326 |
</li> |
327 |
<li> |
328 |
如果您无法使用ssh-agent或者keychain,有可能正在使用的的shell不懂您使用的命令。请垂询ssh-agent和keychain的man页,了解和其他shell打交道的细节。 |
329 |
</li> |
330 |
</ul> |
331 |
|
332 |
</body> |
333 |
</section> |
334 |
</chapter> |
335 |
</guide> |
336 |
|
337 |
|
338 |
|
339 |
-- |
340 |
gentoo-commits@g.o mailing list |