xref: /freebsd/libexec/ftpd/ftpd.8 (revision dc58b3fca5e7a7bb1e9aa640667944d0fe0601cd)
1.\" Copyright (c) 1985, 1988, 1991, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\" 3. Neither the name of the University nor the names of its contributors
13.\"    may be used to endorse or promote products derived from this software
14.\"    without specific prior written permission.
15.\"
16.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26.\" SUCH DAMAGE.
27.\"
28.\"     @(#)ftpd.8	8.2 (Berkeley) 4/19/94
29.\" $FreeBSD$
30.\"
31.Dd June 28, 2022
32.Dt FTPD 8
33.Os
34.Sh NAME
35.Nm ftpd
36.Nd Internet File Transfer Protocol server
37.Sh SYNOPSIS
38.Nm
39.Op Fl 468ABDdEhMmOoRrSUvW
40.Op Fl l Op Fl l
41.Op Fl a Ar address
42.Op Fl P Ar port
43.Op Fl p Ar file
44.Op Fl T Ar maxtimeout
45.Op Fl t Ar timeout
46.Op Fl u Ar umask
47.Sh DESCRIPTION
48The
49.Nm
50utility is the
51Internet File Transfer Protocol
52server process.
53The server uses the
54.Tn TCP
55protocol
56and listens at the port specified with the
57.Fl P
58option or in the
59.Dq ftp
60service specification; see
61.Xr services 5 .
62.Pp
63Available options:
64.Bl -tag -width indent
65.It Fl 4
66When
67.Fl D
68is specified, accept connections via
69.Dv AF_INET
70socket.
71.It Fl 6
72When
73.Fl D
74is specified, accept connections via
75.Dv AF_INET6
76socket.
77.It Fl 8
78Enable transparent UTF-8 mode.
79RFC\ 2640 compliant clients will be told that the character encoding
80used by the server is UTF-8, which is the only effect of the option.
81.Pp
82This option does not enable any encoding conversion for server file names;
83it implies instead that the names of files on the server are encoded
84in UTF-8.
85As for files uploaded via FTP, it is the duty of the RFC\ 2640 compliant
86client to convert their names from the client's local encoding to UTF-8.
87FTP command names and own
88.Nm
89messages are always encoded in ASCII, which is a subset of UTF-8.
90Hence no need for server-side conversion at all.
91.It Fl A
92Allow only anonymous ftp access.
93.It Fl a
94When
95.Fl D
96is specified, accept connections only on the specified
97.Ar address .
98.It Fl B
99With this option set,
100.Nm
101sends authentication success and failure messages to the
102.Xr blacklistd 8
103daemon.  If this option is not specified, no communcation with the
104.Xr blacklistd 8
105daemon is attempted.
106.It Fl D
107With this option set,
108.Nm
109will detach and become a daemon, accepting connections on the FTP port and
110forking children processes to handle them.
111This is lower overhead than starting
112.Nm
113from
114.Xr inetd 8
115and is thus useful on busy servers to reduce load.
116.It Fl d
117Debugging information is written to the syslog using
118.Dv LOG_FTP .
119.It Fl E
120Disable the EPSV command.
121This is useful for servers behind older firewalls.
122.It Fl h
123Disable printing host-specific information, such as the
124server software version or hostname, in server messages.
125.It Fl l
126Each successful and failed
127.Xr ftp 1
128session is logged using syslog with a facility of
129.Dv LOG_FTP .
130If this option is specified twice, the retrieve (get), store (put), append,
131delete, make directory, remove directory and rename operations and
132their filename arguments are also logged.
133By default,
134.Xr syslogd 8
135logs these to
136.Pa /var/log/xferlog .
137.It Fl M
138Prevent anonymous users from creating directories.
139.It Fl m
140Permit anonymous users to overwrite or modify
141existing files if allowed by file system permissions.
142By default, anonymous users cannot modify existing files;
143in particular, files to upload will be created under a unique name.
144.It Fl O
145Put server in write-only mode for anonymous users only.
146RETR is disabled for anonymous users, preventing anonymous downloads.
147This has no effect if
148.Fl o
149is also specified.
150.It Fl o
151Put server in write-only mode.
152RETR is disabled, preventing downloads.
153.It Fl P
154When
155.Fl D
156is specified, accept connections at
157.Ar port ,
158specified as a numeric value or service name, instead of at the default
159.Dq ftp
160port.
161.It Fl p
162When
163.Fl D
164is specified, write the daemon's process ID to
165.Ar file
166instead of the default pid file,
167.Pa /var/run/ftpd.pid .
168.It Fl R
169With this option set,
170.Nm
171will revert to historical behavior with regard to security checks on
172user operations and restrictions on PORT requests.
173Currently,
174.Nm
175will only honor PORT commands directed to unprivileged ports on the
176remote user's host (which violates the FTP protocol specification but
177closes some security holes).
178.It Fl r
179Put server in read-only mode.
180All commands which may modify the local file system are disabled.
181.It Fl S
182With this option set,
183.Nm
184logs all anonymous file downloads to the file
185.Pa /var/log/ftpd
186when this file exists.
187.It Fl T
188A client may also request a different timeout period;
189the maximum period allowed may be set to
190.Ar timeout
191seconds with the
192.Fl T
193option.
194The default limit is 2 hours.
195.It Fl t
196The inactivity timeout period is set to
197.Ar timeout
198seconds (the default is 15 minutes).
199.It Fl U
200This option instructs ftpd to use data ports in the range of
201.Dv IP_PORTRANGE_DEFAULT
202instead of in the range of
203.Dv IP_PORTRANGE_HIGH .
204Such a change may be useful for some specific firewall configurations;
205see
206.Xr ip 4
207for more information.
208.Pp
209Note that option is a virtual no-op in
210.Fx 5.0
211and above; both port
212ranges are identical by default.
213.It Fl u
214The default file creation mode mask is set to
215.Ar umask ,
216which is expected to be an octal numeric value.
217Refer to
218.Xr umask 2
219for details.
220This option may be overridden by
221.Xr login.conf 5 .
222.It Fl v
223A synonym for
224.Fl d .
225.It Fl W
226Do not log FTP sessions to the user accounting database.
227.El
228.Pp
229The file
230.Pa /var/run/nologin
231can be used to disable ftp access.
232If the file exists,
233.Nm
234displays it and exits.
235If the file
236.Pa /etc/ftpwelcome
237exists,
238.Nm
239prints it before issuing the
240.Dq ready
241message.
242If the file
243.Pa /etc/ftpmotd
244exists,
245.Nm
246prints it after a successful login.
247Note the motd file used is the one
248relative to the login environment.
249This means the one in
250.Pa ~ftp/etc
251in the anonymous user's case.
252.Pp
253The ftp server currently supports the following ftp requests.
254The case of the requests is ignored.
255Requests marked [RW] are
256disabled if
257.Fl r
258is specified.
259.Bl -column "Request" -offset indent
260.It Sy Request Ta Sy "Description"
261.It ABOR Ta "abort previous command"
262.It ACCT Ta "specify account (ignored)"
263.It ALLO Ta "allocate storage (vacuously)"
264.It APPE Ta "append to a file [RW]"
265.It CDUP Ta "change to parent of current working directory"
266.It CWD Ta "change working directory"
267.It DELE Ta "delete a file [RW]"
268.It EPRT Ta "specify data connection port, multiprotocol"
269.It EPSV Ta "prepare for server-to-server transfer, multiprotocol"
270.It FEAT Ta "give information on extended features of server"
271.It HELP Ta "give help information"
272.It LIST Ta "give list files in a directory" Pq Dq Li "ls -lgA"
273.It LPRT Ta "specify data connection port, multiprotocol"
274.It LPSV Ta "prepare for server-to-server transfer, multiprotocol"
275.It MDTM Ta "show last modification time of file"
276.It MKD Ta "make a directory [RW]"
277.It MODE Ta "specify data transfer" Em mode
278.It NLST Ta "give name list of files in directory"
279.It NOOP Ta "do nothing"
280.It PASS Ta "specify password"
281.It PASV Ta "prepare for server-to-server transfer"
282.It PORT Ta "specify data connection port"
283.It PWD Ta "print the current working directory"
284.It QUIT Ta "terminate session"
285.It REST Ta "restart incomplete transfer"
286.It RETR Ta "retrieve a file"
287.It RMD Ta "remove a directory [RW]"
288.It RNFR Ta "specify rename-from file name [RW]"
289.It RNTO Ta "specify rename-to file name [RW]"
290.It SITE Ta "non-standard commands (see next section)"
291.It SIZE Ta "return size of file"
292.It STAT Ta "return status of server"
293.It STOR Ta "store a file [RW]"
294.It STOU Ta "store a file with a unique name [RW]"
295.It STRU Ta "specify data transfer" Em structure
296.It SYST Ta "show operating system type of server system"
297.It TYPE Ta "specify data transfer" Em type
298.It USER Ta "specify user name"
299.It XCUP Ta "change to parent of current working directory (deprecated)"
300.It XCWD Ta "change working directory (deprecated)"
301.It XMKD Ta "make a directory (deprecated) [RW]"
302.It XPWD Ta "print the current working directory (deprecated)"
303.It XRMD Ta "remove a directory (deprecated) [RW]"
304.El
305.Pp
306The following non-standard or
307.Ux
308specific commands are supported
309by the
310SITE request.
311.Bl -column Request -offset indent
312.It Sy Request Ta Sy Description
313.It UMASK Ta change umask, e.g. ``SITE UMASK 002''
314.It IDLE Ta set idle-timer, e.g. ``SITE IDLE 60''
315.It CHMOD Ta "change mode of a file [RW], e.g. ``SITE CHMOD 755 filename''"
316.It MD5 Ta "report the files MD5 checksum, e.g. ``SITE MD5 filename''"
317.It HELP Ta give help information
318.El
319.Pp
320Note: SITE requests are disabled in case of anonymous logins.
321.Pp
322The remaining ftp requests specified in Internet RFC 959
323are
324recognized, but not implemented.
325MDTM and SIZE are not specified in RFC 959, but will appear in the
326next updated FTP RFC.
327To avoid possible denial-of-service attacks, SIZE requests against
328files larger than 10240 bytes will be denied if the current transfer
329type is ASCII.
330.Pp
331The ftp server will abort an active file transfer only when the
332ABOR
333command is preceded by a Telnet "Interrupt Process" (IP)
334signal and a Telnet "Synch" signal in the command Telnet stream,
335as described in Internet RFC 959.
336If a
337STAT
338command is received during a data transfer, preceded by a Telnet IP
339and Synch, transfer status will be returned.
340.Pp
341The
342.Nm
343utility interprets file names according to the
344.Dq globbing
345conventions used by
346.Xr csh 1 .
347This allows users to utilize the metacharacters
348.Dq Li \&*?[]{}~ .
349.Pp
350The
351.Nm
352utility authenticates users according to six rules.
353.Bl -enum -offset indent
354.It
355The login name must be in the password data base
356and not have a null password.
357In this case a password must be provided by the client before any
358file operations may be performed.
359.It
360The login name must not appear in the file
361.Pa /etc/ftpusers .
362.It
363The login name must not be a member of a group specified in the file
364.Pa /etc/ftpusers .
365Entries in this file interpreted as group names are prefixed by an "at"
366.Ql \&@
367sign.
368.It
369The user must have a standard shell returned by
370.Xr getusershell 3 .
371.It
372If the user name appears in the file
373.Pa /etc/ftpchroot ,
374or the user is a member of a group with a group entry in this file,
375i.e., one prefixed with
376.Ql \&@ ,
377the session's root will be changed to the directory specified
378in this file or to the user's login directory by
379.Xr chroot 2
380as for an
381.Dq anonymous
382or
383.Dq ftp
384account (see next item).
385See
386.Xr ftpchroot 5
387for a detailed description of the format of this file.
388This facility may also be triggered by enabling the boolean "ftp-chroot"
389capability in
390.Xr login.conf 5 .
391However, the user must still supply a password.
392This feature is intended as a compromise between a fully anonymous
393account and a fully privileged account.
394The account should also be set up as for an anonymous account.
395.It
396If the user name is
397.Dq anonymous
398or
399.Dq ftp ,
400an
401anonymous ftp account must be present in the password
402file (user
403.Dq ftp ) .
404In this case the user is allowed
405to log in by specifying any password (by convention an email address for
406the user should be used as the password).
407When the
408.Fl S
409option is set, all transfers are logged as well.
410.El
411.Pp
412In the last case,
413.Nm
414takes special measures to restrict the client's access privileges.
415The server performs a
416.Xr chroot 2
417to the home directory of the
418.Dq ftp
419user.
420As a special case if the
421.Dq ftp
422user's home directory pathname contains the
423.Pa /./
424separator,
425.Nm
426uses its left-hand side as the name of the directory to do
427.Xr chroot 2
428to, and its right-hand side to change the current directory to afterwards.
429A typical example for this case would be
430.Pa /var/spool/ftp/./pub .
431In order that system security is not breached, it is recommended
432that the
433.Dq ftp
434subtree be constructed with care, following these rules:
435.Bl -tag -width "~ftp/pub" -offset indent
436.It Pa ~ftp
437Make the home directory owned by
438.Dq root
439and unwritable by anyone.
440.It Pa ~ftp/etc
441Make this directory owned by
442.Dq root
443and unwritable by anyone (mode 555).
444The files pwd.db (see
445.Xr passwd 5 )
446and
447.Xr group 5
448must be present for the
449.Xr ls 1
450command to be able to produce owner names rather than numbers.
451The password field in
452.Xr passwd 5
453is not used, and should not contain real passwords.
454The file
455.Pa ftpmotd ,
456if present, will be printed after a successful login.
457These files should be mode 444.
458.It Pa ~ftp/pub
459This directory and the subdirectories beneath it should be owned
460by the users and groups responsible for placing files in them,
461and be writable only by them (mode 755 or 775).
462They should
463.Em not
464be owned or writable by
465.Dq ftp
466or its group, otherwise guest users
467can fill the drive with unwanted files.
468.El
469.Pp
470If the system has multiple IP addresses,
471.Nm
472supports the idea of virtual hosts, which provides the ability to
473define multiple anonymous ftp areas, each one allocated to a different
474internet address.
475The file
476.Pa /etc/ftphosts
477contains information pertaining to each of the virtual hosts.
478Each host is defined on its own line which contains a number of
479fields separated by whitespace:
480.Bl -tag -offset indent -width hostname
481.It hostname
482Contains the hostname or IP address of the virtual host.
483.It user
484Contains a user record in the system password file.
485As with normal anonymous ftp, this user's access uid, gid and group
486memberships determine file access to the anonymous ftp area.
487The anonymous ftp area (to which any user is chrooted on login)
488is determined by the home directory defined for the account.
489User id and group for any ftp account may be the same as for the
490standard ftp user.
491.It statfile
492File to which all file transfers are logged, which
493defaults to
494.Pa /var/log/ftpd .
495.It welcome
496This file is the welcome message displayed before the server ready
497prompt.
498It defaults to
499.Pa /etc/ftpwelcome .
500.It motd
501This file is displayed after the user logs in.
502It defaults to
503.Pa /etc/ftpmotd .
504.El
505.Pp
506Lines beginning with a '#' are ignored and can be used to include
507comments.
508.Pp
509Defining a virtual host for the primary IP address or hostname
510changes the default for ftp logins to that address.
511The 'user', 'statfile', 'welcome' and 'motd' fields may be left
512blank, or a single hyphen '-' used to indicate that the default
513value is to be used.
514.Pp
515As with any anonymous login configuration, due care must be given
516to setup and maintenance to guard against security related problems.
517.Pp
518The
519.Nm
520utility has internal support for handling remote requests to list
521files, and will not execute
522.Pa /bin/ls
523in either a chrooted or non-chrooted environment.
524The
525.Pa ~/bin/ls
526executable need not be placed into the chrooted tree, nor need the
527.Pa ~/bin
528directory exist.
529.Sh FILES
530.Bl -tag -width ".Pa /var/run/ftpd.pid" -compact
531.It Pa /etc/ftpusers
532List of unwelcome/restricted users.
533.It Pa /etc/ftpchroot
534List of normal users who should be chroot'd.
535.It Pa /etc/ftphosts
536Virtual hosting configuration file.
537.It Pa /etc/ftpwelcome
538Welcome notice.
539.It Pa /etc/ftpmotd
540Welcome notice after login.
541.It Pa /var/run/ftpd.pid
542Default pid file for daemon mode.
543.It Pa /var/run/nologin
544Displayed and access refused.
545.It Pa /var/log/ftpd
546Log file for anonymous transfers.
547.It Pa /var/log/xferlog
548Default place for session logs.
549.It Pa /var/spool/ftp
550Recommended directory for the FTP root directory
551(the home directory of the ftp user).
552.El
553.Sh SEE ALSO
554.Xr ftp 1 ,
555.Xr umask 2 ,
556.Xr getusershell 3 ,
557.Xr ftpchroot 5 ,
558.Xr login.conf 5 ,
559.Xr inetd 8 ,
560.Xr syslogd 8
561.Sh HISTORY
562The
563.Nm
564utility appeared in
565.Bx 4.2 .
566IPv6 support was added in WIDE Hydrangea IPv6 stack kit.
567.Sh BUGS
568The server must run as the super-user
569to create sockets with privileged port numbers.
570It maintains
571an effective user id of the logged in user, reverting to
572the super-user only when binding addresses to sockets.
573The
574possible security holes have been extensively
575scrutinized, but are possibly incomplete.
576