aboutsummaryrefslogtreecommitdiffstats
path: root/security/safesh/src/safesh.1
blob: 1ba321d6c1570f7bbc09fd4e959059c1884f23f5 (plain) (blame)
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
.\"-
.\" Copyright (c) 2002 Eivind Eklund
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer
.\"    in this position and unchanged.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in the
.\"    documentation and/or other materials provided with the distribution.
.\" 3. The name of the author may not be used to endorse or promote products
.\"    derived from this software without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
.\" $FreeBSD$
.\"
.Dd January 26, 2002
.Dt SAFESH 1
.Sh NAME
.Nm safesh
.Nd safe key manager for OpenSSH
.Sh SYNOPSIS
.Nm 
.Sm off
.Op Ar user@
.Ar host
.Sm on
.Op Ar "-- ssh-parameters ..."
.Nm safeshinstall
.Sm off
.Op Ar user@
.Ar host
.Sm on
.Nm cvs-safesh
.Sm off
.Op Ar user@
.Ar host
.Sm on
.Op Ar command
.Nm scpsh
.Sm off
.Op Ar user@
.Ar host
.Sm on
.Sh DESCRIPTION
NOTE: This text often refers to $VARIABLE in description.
What each of the references will be replaced with when
.Nm
runs is described at the end of the manpage.
.Pp
.Nm
automatically creates one DSA key (called an identity) for each host you
connect to, and store this in a separate agent for each host.
It is also capable of adding keys for other hosts to this agent, so you can
use it for restricted forwarded of authentication.
Because each host use its own
.Xr ssh-agent 1 ,
the hosts you forward authentication to can only get at the authentication for
the hosts you specifically say it should be able to get at.
.Pp
When run,
.Nm
.Bl -enum
.It
Normalizes the hostname you are talking about, using the $HOME/.safesh/map file.
.It
Checks if the user and host has an ssh dsa key in $HOME/.safesh, and creates one using 
.Xr ssh-keygen 1
if it does not.
The DSA key is stored in $HOME/.safesh/$USER@$HOST-$PORT/dsa_id.
You will be asked for a passphrase when the key is created.
Note that if you use the same passphrase for all
.Nm
keys, you will only be asked for the passphrase once per host you connect to.
If you use different passphrases, you will be asked once per forwarded key
for each host you connect to (after a machine startup.)
.It
Checks if you have the
.Xr ssh-agent 1
for this host running, and starts it if not.
.It
Checks what keys you are supposed to have active when connecting to this host
(the key for the host and any keys listed in $HOME/.safesh/$USER@$HOST-$PORT/extra_keys),
and which of these are missing from the active agent.
.It
If any identities were missing from the agent, it executes
.Xr ssh-add 1
to add them to the agent.
.It
Executes
.Xr ssh 1
with either $USER@$HOST or the extra command line supplied by the user.
.El
.Sh BASIC CONCEPT DESCRIPTION
.Nm
is an authentication manager for OpenSSH.
It is an attempt at making it easy to use the built-in authentication features
of OpenSSH securely.
By default, the SSH security model is that all hosts the
user connect to are trusted, and are given complete access - including the
ability to authenticate as the user towards other hosts if the user is running
.Xr ssh-agent 1 .
OpenSSH has improved this security model somewhat by not forwarding ssh
authentication by default, but still allows the host that you connect to
to grab your credentials and authenticate as you to anybody else when you
do authentication forwarding to it.
.Sh SIMPLE HOWTO
Starting to make use of
.Nm
is trivial:
.Bl -enum
.It
Do 
.Dl % safeshinstall <[user@]hostname>
This will ask for a passphrase (three times), create a directory
$HOME/.safesh/<user>@<hostname>-22, which contains authentication
data for your user at <hostname>, and add the contents of
$HOME/.safesh/<user>@<hostname>-22/id_dsa.pub to
$HOME/.ssh/authorized_keys2 on the host you connect to.
The latter will result in
.Xr ssh 1
asking for authentication in the fashion you already use (most likely by
asking for your password.)
.It
Log in with 
.Li "safesh <hostname>"
from now on.
This will ask you for a passphrase if you have not logged into that host this
session, and otherwise just let right in.
.El
.Sh UTILITY COMMANDS
.Nm
ships with two utility hacks to work around the fact that it is not a complete
.Xr ssh 1
replacement,
.Nm scpsh
and
.Nm cvs-safesh .
.Pp
.Nm scpsh
is for supporting use of
.Xr scp 1
with
.Nm .
.Nm scpsh
.Sm off
.Op Ar user@
.Ar host
.Sm on
will start a new interactive shell (using the
.Ev SHELL
environment variable to determine which it should be), with the environment
variables for using
.Xr ssh-agent 1
to authenticate to [user@]host already set.
This allows use of 
.Xr scp 1
without having to type passwords to authenticate.
.Pp
.Nm cvs-safesh
makes it easy to use
.Nm
along with
.Xr cvs 1
and other programs that use
.Xr rsh 1
or
.Xr ssh 1
with the format 
.Qq Li "ssh <user@host> <command>"
or 
.Qq Li "ssh <host> <command>" .
To use with
.Xr cvs 1 ,
just set
.Ev CVS_RSH
to
.Qq Li cvs-safesh
instead of
.Qq Li ssh .
.Pp
.Sh FILES
.Bl -tag -width "$HOME/.safesh" -compact
.It Pa $HOME/.safesh/
Directory containing information for
.Nm .
.Pp
.It Pa $HOME/.safesh/map
Mapping file for
.Nm ,
describing how to map host names to their canonical form.
This is usually used to map short names to their long form.
The format of the file is one mapping per line, what it is mapped from as the
first word, what it is mapped to as the second.
.Pp
It is also possible to use this to map DNS names to their safe form by having
the name of the host as the first parameter, and the name of the host with a
period (.) at the end as the second parameter.
E.g, "freefall.freebsd.org freefall.freebsd.org."
.Pp
.It Pa $HOME/.safesh/$USER@$HOST-$PORT/
Directory with data for a particular hostname.
Automatically generated on first connect to a host with
.Nm .
.Pp
.It Pa $HOME/.safesh/$USER@$HOST-$PORT/dsa_id
Private key for use to authenticate as $USER@$HOST.
Automatically generated on first connect to a host with
.Nm .
.Pp
.It Pa $HOME/.safesh/$USER@$HOST-$PORT/dsa_id.pub
Public key for use by $HOST to authenticate $USER.
To connect to $HOST as $USER using 
.Nm
without giving a password, add the contents of this file
to the end of $HOME/.ssh/authorized_keys2.
Automatically generated on first connect to a host with
.Nm .
.Pp
.It Pa $HOME/.safesh/$USER@$HOST-$PORT/$AUTHTARGET
Private key for use when $HOST authenticates towards $AUTHTARGET.
This is used in preference to $HOME/.safesh/$AUTHTARGET/dsa_id for authentication
forwarding through $HOST to $AUTHTARGET.
The file is only used if $AUTHTARGET is listed in $HOME/.safesh/$USER@$HOST-$PORT/extra_keys.
This file is not generated automatically by
.Nm .
It is only present if you have generated it using
.Xr ssh-keygen 1 .
Note that it is usually more than useless (can pose a security risk) to copy a
key used for other authentication to this location.
.Pp
The use of explict authentication files for authentication forwarding is
primarily for protection against the case where the machine you run
.Nm
on is compromised.
Using this file, you can use a separate passphrase from the one used for the
key for connecting directly to $AUTHTARGET; that key need not even exist.
By using IP restrictions in the authorized_keys file for the key, you can make
sure that the host
.Nm
runs on cannot connect to $AUTHTARGET using the authentication forwarding
key.
The use of a separate forwarding key can also be used in combination with a
modified SSH to log which key was used where, and thus track key propagation.
.Pp
.It Pa $HOME/.safesh/$USER@$HOST-$PORT/$AUTHTARGET.pub
Public key corresponding to the private key described above.
.Pp
.It Pa $HOME/.safesh/$USER@$HOST-$PORT/extra_keys
List of extra keys to make available for this host.
Each line in the file is first attempted matched against the host/user/port
database in $HOME/.safesh/.
Username and/or port is added if just the hostname is specified extra_keys, and
the hostname is always normalized using the map file.
If a key exists in $HOME/.safesh/, 
.Nm
attempts to add that.
Otherwise, it first tries to look for the line as a file relative to /, then
relative to $HOME.
If it does not find either of these,
.Nm
will exit with an error message.
If it finds one, it will add it using
.Xr ssh-add 1 .
.Pp
.It Pa $HOME/.safesh/$USER@$HOST-$PORT/activeagent-$YOURHOST.sh
Bourne shell (see
.Xr sh 1 ,
.Xr bash 1 ,
.Xr zsh 1 )
script for setting up the environment variables for the particular ssh-agent used for this host.
Only valid if
.Nm
has been run against that host as this user since the machine 
.Nm
runs on was last booted.
Note that this file most be source'd, not just run as a shell script.
.Pp
.It Pa $HOME/.safesh/$USER@$HOST-$PORT/activeagent-$YOURHOST.csh
CSH (see
.Xr csh 1 ,
.Xr tcsh 1 )
script for setting up the environment variables for the particular ssh-agent used for this host.
Only valid if
.Nm
has been run against that host as this user since the machine 
.Nm
runs on was last booted.
Note that this file most be source'd, not just run as a shell script.
.El
.Pp
.Sh AUTHORS
.Nm
was written by
.An Eivind Eklund Aq eivind@FreeBSD.org .
.Sh SEE ALSO
.Xr ssh 1 ,
.Xr ssh-add 1 ,
.Xr ssh-agent 1 ,
.Xr ssh-keygen 1 .
.Pp
.Sh KNOWN ISSUES
.Nm
does not handle whitespace in filenames specified in extra_keys correctly.
.Pp
The ssh-agents that are started by will hang around until next reboot unless
you put 'killall ssh-agent' in .logout or similar.
This allows any login to your account to use your authentication towards
machines you have connected to (including anybody with root on the box),
persisting after you log out.
You must always assume that root can grab your authentication at the moment
you run do it, so this is only an issue in that the authentication stays
available longer.
This is not resolvable without rewriting ssh-agent.
.Pp
.Sh MISSING FEATURES
.Bl -tag -width "mmmm" -compact
.It Pa Two-step secure SSH with an untrusted host in the middle
It is possible to use the port forwarding capability of ssh to forward
authentication through another server - without allowing the other server to
indepently authenticate to a third party, and without allowing it to see
what is going on in your connection.
This is based on just forwarding a tunnel through the untrusted host, and
doing direct authentication to the server on the other side.
With the present version of OpenSSH, this has the problem of leaving the
actual port forwarding open while the tunnel is open - allowing other users to
set up their own tunnels, and weakening another side of the security model.
.Pp
.It Pa Read out fingerprints
.Nm
should make it trivial to retrieve the fingerprint for
.Bl -enum
.It
The host it is running on.
This must presently done with "ssh-keygen -l /etc/ssh/ssh_host_key.pub" (to get
the fingerprint for SSH 1) and "ssh-keygen -l -f /etc/ssh/ssh_host_dsa_key"
(for SSH 2).
.It 
Other hosts, as registered in the known_host file on the host it is running
on.
This must presently be done by manual inspection.
.El
.Pp
.It Pa Merge known_hosts
.Nm
should make it trivial to merge known_hosts and known_hosts2 with ones from
another host, including retrieving and uploading known_hosts as appropriate.
.Pp
.It Pa Manage .ssh/authorized_keys2
.Nm
should be able to automatically remove keys from the authorized_keys2 file
on other machines, to make everything about the
.Nm
process self-contained.
.Pp
.It Pa Manage setup of key limitations
When managing authorized_keys2, it is also reasonable to manage key limitation
in this.
IP restrictions ("from=") should be handled to make it easy to create setups
where the local machine do not have direct access to a target.
Command restrictions etc would be good to have just for completeness.
.Pp
.It Pa Emulate the entire ssh syntax
Presently, the
.Nm
command has a fairly weird syntax.
This is because it is a fairly quick hack, just made to be usable.
Later, it would be nice to rewrite it to be fully compatible with
.Xr ssh 1 .
This would allow use as a drop-in replacement.
.Pp
.It Pa Description of the trust/threat/security model
It would be nice to have a complete description of the normal SSH threat model
as well as the
.Nm
threat model, in order to make people fully conscious of their own model.
.Pp
.It Pa Emulate scp
.Xr scp 1
is very useful, and the only way to use it with
.Nm
at the moment is through a subshell created by
.Nm scpsh .
An ideal
.Nm
implementation would include wrapping of
.Xr scp 1 ,
too.
.Pp
.El
.Sh VARIABLE REPLACEMENT IN DESCRIPTIONS
.Bl -tag -width "$HOME/.safesh" -compact
.It Pa $HOME
is replaced with the path your home directory,
.It Pa $HOST
is replaced with the name of the host you are running
.Nm
towards.
This is the machine you are
.Xr ssh 1 ing
into.
.It Pa $YOURHOST
is replaced with the name of the host you are running
.Nm
on, as output by
.Xr hostname 1 .
This is the name of the machine you are
.Xr ssh 1 ing
from.
The use of $YOURHOST makes
.Nm
safe to use with NFS-mounted home directories.
.It Pa $AUTHTARGET
is replaced with the authentication target for an authentication forwarding.
This is
.Pa not
the same as $HOST.
$AUTHTARGET is a machine you are
.Xr ssh 1 ing
to
.Pa from
$HOST.
The format of $AUTHTARGET is <user>@<somehost>-<someport>, where <user>
defaults to the username you run
.Nm
as, and <someport> default to 22 (and it is not possible to set anything
else at this time.)
.It Pa $USER
is replaced with The username used on $HOST; defaults to the same as the
username you have on $YOURHOST, but will be different if you do safesh
user@host instead of just safesh host.
.It Pa $PORT
The port used on $HOST.
Presently always 22.
.El
.Pp