summaryrefslogtreecommitdiff
path: root/lib/ssh/doc/src/ssh_file.xml
blob: e97bb5b37fa572d4ebdb961a7da748c58b0d5028 (plain)
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
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE erlref SYSTEM "erlref.dtd">

<erlref>
  <header>
    <copyright>
      <year>2018</year><year>2022</year>
      <holder>Ericsson AB. All Rights Reserved.</holder>
    </copyright>
    <legalnotice>
      Licensed under the Apache License, Version 2.0 (the "License");
      you may not use this file except in compliance with the License.
      You may obtain a copy of the License at
      
      http://www.apache.org/licenses/LICENSE-2.0

      Unless required by applicable law or agreed to in writing, software
      distributed under the License is distributed on an "AS IS" BASIS,
      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      See the License for the specific language governing permissions and
      limitations under the License.

    </legalnotice>
    
    <title>ssh_file</title>
    <prepared></prepared>
    <docno></docno>
    <date></date>
    <rev></rev>
  </header>
  <module since="OTP 21.2">ssh_file</module>
  <modulesummary>Default callback module for the client's and server's database operations in the ssh application</modulesummary>
  <description>
    <p>This module is the default callback handler for the client's and the server's user and host "database" operations.
    All data, for instance key pairs, are stored in files in the normal file system. This page documents the files, where they
    are stored and configuration options for this callback module.
    </p>
    <p>The intention is to be compatible with the
    <url href="http://www.openssh.com">OpenSSH</url>
    storage in files. Therefore it mimics directories and filenames of
    <url href="http://www.openssh.com">OpenSSH</url>.
    </p>

    <p>Ssh_file implements the <seeerl marker="ssh:ssh_server_key_api">ssh_server_key_api</seeerl> and
    the <seeerl marker="ssh:ssh_client_key_api">ssh_client_key_api</seeerl>.
    This enables the user to make an own interface using for example a database handler.
    </p>
    <p>Such another callback module could be used by setting the option
    <seetype marker="ssh:ssh#key_cb_common_option"><c>key_cb</c></seetype>
    when starting a client or a server (with for example
    <seemfa marker="ssh:ssh#connect/3">ssh:connect</seemfa>,
    <seemfa marker="ssh:ssh#daemon/2">ssh:daemon</seemfa> of
    <seemfa marker="ssh:ssh#shell/1">ssh:shell</seemfa>
    ).
    </p>

    <note>
      <p>The functions are <i>Callbacks</i> for the SSH app. They are not intended to be called from the user's code!
      </p>
    </note>
  </description>

  <section>
    <title>Files, directories and who uses them</title>
    <section>
      <title>Daemons</title>
      <p>Daemons uses all files stored in the <seeerl marker="#SYSDIR">SYSDIR</seeerl> directory.
      </p>
      <p>Optionaly, in case of <c>publickey</c> authorization, one or more of the remote user's public keys
      in the <seeerl marker="#USERDIR">USERDIR</seeerl> directory are used.
      See the files 
      <seeerl marker="#FILE-authorized_keys"><c>USERDIR/authorized_keys</c></seeerl> and
      <seeerl marker="#FILE-authorized_keys2"><c>USERDIR/authorized_keys2</c></seeerl>.
      </p>
    </section>

    <section>
      <title>Clients</title>
      <p>Clients uses all files stored in the <seeerl marker="#USERDIR">USERDIR</seeerl> directory.
      </p>
    </section>

    <section>
      <title>Directory contents</title>
      <taglist>
	<tag><marker id="LOCALUSER"/>LOCALUSER</tag>
	<item><p>The user name of the OS process running the Erlang virtual machine (emulator).</p>
	</item>

	<tag><marker id="SYSDIR"/>SYSDIR</tag>
	<item><p>This is the directory holding the server's files:</p>
	<list>
	  <item><marker id="FILE-ssh_host_STAR_key"/>
	        <marker id="FILE-ssh_host_dsa_key"/><c>ssh_host_dsa_key</c> - private dss host key (optional)</item>
	  <item><marker id="FILE-ssh_host_rsa_key"/><c>ssh_host_rsa_key</c> - private rsa host key (optional)</item>
	  <item><marker id="FILE-ssh_host_ecdsa_key"/><c>ssh_host_ecdsa_key</c> - private ecdsa host key (optional)</item>
	  <item><marker id="FILE-ssh_host_ed25519_key"/><c>ssh_host_ed25519_key</c> - private eddsa host key for curve 25519 (optional)</item>
	  <item><marker id="FILE-ssh_host_ed448_key"/><c>ssh_host_ed448_key</c> - private eddsa host key for curve 448 (optional)</item>
	</list>
	<p>The key files could be generated with OpenSSH's ssh-keygen command.</p>
	<p>At least one host key must be defined. The default value of SYSDIR is <marker id="#/etc/ssh"/><c>/etc/ssh</c>.
	</p>
	<p>For security reasons, this directory is normally accessible only to the root user.
	</p>
	<p>To change the SYSDIR, see the <seetype marker="#system_dir_daemon_option">system_dir</seetype> option.
	</p>
	</item>

	<tag><marker id="USERDIR"/>USERDIR</tag>
	<item><p>This is the directory holding the files:</p>
	<list>
	  <item><marker id="FILE-authorized_keys"/><c>authorized_keys</c>
	  and, as second alternative
	  <marker id="FILE-authorized_keys2"/><c>authorized_keys2</c> - 
	  the user's public keys are stored concatenated in one of those files.
	  <p>It is composed of lines as for
	  <url href="https://man.openbsd.org/sshd#AUTHORIZED_KEYS_FILE_FORMAT">OpenSSH</url>:</p>
	  <pre>(options)? keytype base64-encoded-key comment</pre>
	  <p>where</p>
	  <code>
options :: option(,option)*
option :: % All options are skipped
keytype :: 'ssh-dsa'
         | 'ssh-rsa'
         | 'ssh-ecdsa-nistp256'
	 | 'ssh-ecdsa-nistp384'
         | 'ssh-ecdsa-nistp521'
         | 'ssh-ed25519'
	 | 'ssh-ed448'
base64-encoded-key :: % The user's public key
comment :: % Comments are skipped
	  </code>
	  </item>
	  <item><marker id="FILE-known_hosts"/><c>known_hosts</c> - host keys from hosts visited
	  concatenated. The file is created and used by the client.
	  <p>It is composed of lines as for
	  <url href="https://man.openbsd.org/sshd#SSH_KNOWN_HOSTS_FILE_FORMAT">OpenSSH</url>:</p>
	  <pre>(option)? pattern(,pattern)* keytype key (comment)?</pre>
	  <p>where</p>
	  <code>
option :: '@revoked'
pattern :: host | '[' host ']:' port
host :: ip-address | hostname | '*'
port :: portnumber | '*'
keytype :: 'ssh-dsa'
         | 'ssh-rsa'
         | 'ssh-ecdsa-nistp256'
	 | 'ssh-ecdsa-nistp384'
         | 'ssh-ecdsa-nistp521'
         | 'ssh-ed25519'
	 | 'ssh-ed448'
key :: % encoded key from eg ssh_host_*.pub
</code>
	  </item>
	  <item><marker id="FILE-id_STAR"/>
	        <marker id="FILE-id_dsa"/><c>id_dsa</c> - private dss user key (optional)</item>
	  <item><marker id="FILE-id_rsa"/><c>id_rsa</c> - private rsa user key (optional)</item>
	  <item><marker id="FILE-id_ecdsa"/><c>id_ecdsa</c> - private ecdsa user key (optional)</item>
	  <item><marker id="FILE-id_ed25519"/><c>id_ed25519</c> - private eddsa user key for curve 25519 (optional)</item>
	  <item><marker id="FILE-id_ed448"/><c>id_ed448</c> - private eddsa user key for curve 448 (optional)</item>
	</list>
	<p>The key files could be generated with OpenSSH's ssh-keygen command.</p>
	<p>The default value of USERDIR is <c>/home/</c><seeerl marker="#LOCALUSER"><c>LOCALUSER</c></seeerl><c>/.ssh</c>.
	</p>
	<p>To change the USERDIR, see the <seetype marker="#user_dir_common_option">user_dir</seetype> option
	</p>
	</item>
      </taglist>
    </section>
  </section>

  <datatypes>
    <datatype_title>Options for the default ssh_file callback module</datatype_title>
    <datatype>
      <name name="user_dir_common_option"/>
      <desc>
	<p>Sets the <seeerl marker="#USERDIR">user directory</seeerl>.</p>
      </desc>
    </datatype>

    <datatype>
      <name name="user_dir_fun_common_option"/>
      <name name="user2dir"/>
      <desc>
	<p>Sets the <seeerl marker="#USERDIR">user directory</seeerl> dynamically
	by evaluating the <c>user2dir</c> function.
	</p>
      </desc>
    </datatype>

    <datatype>
      <name name="system_dir_daemon_option"/>
      <desc>
        <p>Sets the <seeerl marker="#SYSDIR">system directory</seeerl>.</p>
      </desc>
    </datatype>

    <datatype>
      <name name="pubkey_passphrase_client_options"/>
      <desc>
	<p>If the user's DSA, RSA or ECDSA key is protected by a passphrase, it can be
	supplied with thoose options.
	</p>
	<p>Note that EdDSA passhrases (Curves 25519 and 448) are not implemented.</p>
      </desc>
    </datatype>

    <datatype>
      <name name="optimize_key_lookup"/>
      <desc>
        <p>Make the handling of large files fast by setting <c>time</c>, but this will use more memory.
	The <c>space</c> variant shrinks the memory requirements, but with a higher time consumption.
	</p>
	<p>To set it, set the
	option <c>{key_cb, {ssh_file, [{optimize,TimeOrSpace}]}</c> in the call of
	<seemfa marker="ssh#connect/3">"ssh:connect/3</seemfa>,
	<seemfa marker="ssh#daemon/2">ssh:daemon/2</seemfa>
	or similar function call that initiates an ssh connection.
	</p>
      </desc>
    </datatype>

    <datatype>
      <name name="key"/>
      <desc>
	<p>The key representation.</p>
      </desc>
    </datatype>

    <datatype>
      <name name="experimental_openssh_key_v1"/>
      <name name="openssh_key_v1_attributes"/>
      <desc>
	<p>Types for the experimental implementaition of the <c>openssh_key_v1</c> format.
	The <c>#ECPoint{}</c> and <c>ECPrivateKey{}</c> are not used for Edwards curves
	(ed25519 and ed448), but will be in next major release.
	</p>
      </desc>
      </datatype>

  </datatypes>

  <funcs>
    <func>
      <name since="OTP 21.2" name="host_key" arity="2"/>
      <fsummary></fsummary>
      <desc>
	<p><strong>Types and description</strong></p>
	<p>See the api description in
	<seemfa marker="ssh:ssh_server_key_api#Module:host_key/2">ssh_server_key_api, Module:host_key/2</seemfa>.
	</p>
	<p><strong>Options</strong></p>
	<list>
	  <item><seetype marker="#system_dir_daemon_option">system_dir</seetype></item>
	  <!-- item>dsa_pass_phrase</item -->
	  <!-- item>rsa_pass_phrase</item -->
	  <!-- item>ecdsa_pass_phrase</item -->
	</list>
	<p><strong>Files</strong></p>
	<list>
	  <item><seeerl marker="#FILE-ssh_host_rsa_key"><c>SYSDIR/ssh_host_rsa_key</c></seeerl></item>
	  <item><seeerl marker="#FILE-ssh_host_dsa_key"><c>SYSDIR/ssh_host_dsa_key</c></seeerl></item>
	  <item><seeerl marker="#FILE-ssh_host_ecdsa_key"><c>SYSDIR/ssh_host_ecdsa_key</c></seeerl></item>
          <item><seeerl marker="#FILE-ssh_host_ed25519_key"><c>SYSDIR/ssh_host_ed25519_key</c></seeerl></item>
          <item><seeerl marker="#FILE-ssh_host_ed448_key"><c>SYSDIR/ssh_host_ed448_key</c>c></seeerl></item>
	</list>
      </desc>
    </func>

    <func>
      <name since="OTP 21.2" name="is_auth_key" arity="3"/>
      <fsummary></fsummary>
      <desc>
	<p><strong>Types and description</strong></p>
	<p>See the api description in
	<seemfa marker="ssh:ssh_server_key_api#Module:is_auth_key/3">ssh_server_key_api: Module:is_auth_key/3</seemfa>.
	</p>
	<p><strong>Options</strong></p>
	<list>
	  <item><seetype marker="#user_dir_fun_common_option">user_dir_fun</seetype></item>
	  <item><seetype marker="#user_dir_common_option">user_dir</seetype></item>
	</list>
	<p><strong>Files</strong></p>
	<list>
	  <item><seeerl marker="#FILE-authorized_keys"><c>USERDIR/authorized_keys</c></seeerl></item>
	  <item><seeerl marker="#FILE-authorized_keys2"><c>USERDIR/authorized_keys2</c></seeerl></item>
	</list>
	<p>This functions discards all options in the begining of the lines of thoose files when reading them.
	</p>
      </desc>
    </func>

    <func>
      <name since="OTP 23.0" name="add_host_key" arity="4"/>
      <fsummary></fsummary>
      <desc>
	<p><strong>Types and description</strong></p>
	<p>See the api description in
	<seemfa marker="ssh:ssh_client_key_api#Module:add_host_key/4">ssh_client_key_api, Module:add_host_key/4</seemfa>.
	</p>
	<marker id="add_host_key-3"/>
	<p>Note that the alternative, the old
	<seemfa marker="ssh:ssh_client_key_api#Module:add_host_key/3">Module:add_host_key/3</seemfa>
	is no longer supported by <c>ssh_file</c>.
	</p>
	<p><strong>Option</strong></p>
	<list>
	  <item><seetype marker="#user_dir_common_option">user_dir</seetype></item>
	</list>
	<p><strong>File</strong></p>
	<list>
	  <item><seeerl marker="#FILE-known_hosts"><c>USERDIR/known_hosts</c></seeerl></item>
	</list>
      </desc>
    </func>

    <func>
      <name since="OTP 23.0" name="is_host_key" arity="5"/>
      <fsummary></fsummary>
      <desc>
	<p><strong>Types and description</strong></p>
	<p>See the api description in
	<seemfa marker="ssh:ssh_client_key_api#Module:is_host_key/5">ssh_client_key_api, Module:is_host_key/5</seemfa>.
	</p>
	<marker id="is_host_key-4"/>
	<p>Note that the alternative, the old
	<seemfa marker="ssh:ssh_client_key_api#Module:is_host_key/4">Module:is_host_key/4</seemfa>
	is no longer supported by <c>ssh_file</c>.
	</p>
	<p><strong>Option</strong></p>
	<list>
	  <item><seetype marker="#user_dir_common_option">user_dir</seetype></item>
	</list>
	<p><strong>File</strong></p>
	<list>
	  <item><seeerl marker="#FILE-known_hosts"><c>USERDIR/known_hosts</c></seeerl></item>
	</list>
      </desc>
    </func>

    <func>
      <name since="OTP 21.2" name="user_key" arity="2"/>
      <fsummary></fsummary>
      <desc>
	<p><strong>Types and description</strong></p>
	<p>See the api description in
	<seemfa marker="ssh:ssh_client_key_api#Module:user_key/2">ssh_client_key_api, Module:user_key/2</seemfa>.
	</p>
	<p><strong>Options</strong></p>
	<list>
	  <item><seetype marker="#user_dir_common_option">user_dir</seetype></item>
	  <item><seetype marker="#pubkey_passphrase_client_options">dsa_pass_phrase</seetype></item>
	  <item><seetype marker="#pubkey_passphrase_client_options">rsa_pass_phrase</seetype></item>
	  <item><seetype marker="#pubkey_passphrase_client_options">ecdsa_pass_phrase</seetype></item>
	</list>
	<p>Note that EdDSA passhrases (Curves 25519 and 448) are not implemented.</p>
	<p><strong>Files</strong>
	</p>
	<list>
	  <item><seeerl marker="#FILE-id_dsa"><c>USERDIR/id_dsa</c></seeerl></item>
	  <item><seeerl marker="#FILE-id_rsa"><c>USERDIR/id_rsa</c></seeerl></item>
	  <item><seeerl marker="#FILE-id_ecdsa"><c>USERDIR/id_ecdsa</c></seeerl></item>
	  <item><seeerl marker="#FILE-id_ed25519"><c>USERDIR/id_ed25519</c></seeerl></item>
	  <item><seeerl marker="#FILE-id_ed448"><c>USERDIR/id_ed448</c></seeerl></item>
	</list>
      </desc>
    </func>

    <func>
      <name since="OTP 24.0" name="decode" arity="2"/>
      <fsummary></fsummary>
      <desc>
	<p>Decodes an SSH file-binary.</p>
	<p>If <c>Type</c> is <c>public_key</c> the binary can be either
	an RFC4716 public key or an OpenSSH public key.</p>
	<note>
	  <p>The following key types have been renamed from the deprecated
	  <seemfa marker="public_key:public_key#ssh_decode/2">public_key:ssh_decode/2</seemfa>:</p>
	  <list>
	    <item>rfc4716_public_key -> rfc4716_key</item>
	    <item>openssh_public_key -> openssh_key</item>
	  </list>
	</note>
	<note><p>The implementation of the <c>openssh_key_v1</c> format is still experimental.</p></note>
      </desc>
    </func>
    
    <func>
      <name since="OTP 24.0" name="encode" arity="2"/>
      <fsummary></fsummary>
      <desc>
	<p>Encodes a list of SSH file entries (public keys and attributes) to a binary.</p>
	<note>
	  <p>The following key types have been renamed from the deprecated
	  <seemfa marker="public_key:public_key#ssh_encode/2">public_key:ssh_encode/2</seemfa>:</p>
	  <list>
	    <item>rfc4716_public_key -> rfc4716_key</item>
	    <item>openssh_public_key -> openssh_key</item>
	  </list>
	</note>
	<note><p>The implementation of the <c>openssh_key_v1</c> format is still experimental.</p></note>
      </desc>
    </func>

  </funcs>

</erlref>