In the previous chapter, we saw how to use clients to access other systems. This is only half the picture, of course. At the other end of the link, we need servers to provide this service. For each client, there is a server (a daemon) whose name is usually derived from the client name by adding a d to it:
| Client | Server |
|---|---|
| ssh | sshd |
| telnet | telnetd |
| ftp | |
| rsync | rsyncd |
| (browser) | httpd |
| (NFS) | nfsd |
In addition to these servers, we look at a few others in other chapters:
Some servers don’t need any configuration, and about all you need to do is to start them. Others, like web servers, can be very complicated. None of the complication is related to FreeBSD. For example, the issues involved in configuring apache are the same whether you run it with FreeBSD,
If you look at /etc/services, you'll find that there are over 800 services available, most of which are only supported on a small number of machines. It's not always the best idea to start up a daemon for every possible service you may want to offer. IP supplies an alternative: inetd, the Internet daemon, sometimes called a super-server, which listens on multiple ports. When a request arrives on a specific port, inetd starts a daemon specific to the port. For example, FreeBSD supports anonymous ftp, but most people don't receive enough requests to warrant having the ftp daemon, ftpd, running all the time. Instead, inetd starts an ftpd when a request comes in on port 21.
At startup, inetd reads a configuration file /etc/inetd.conf to determine which ports to monitor and what to do when a message comes in. Here's an excerpt:
#$FreeBSD: src/etc/inetd.conf,v 1.58 2002/08/09 17:34:13 gordon Exp $ # #Internet server configuration database # #ftp stream tcp nowait root /usr/libexec/lukemftpd ftpd -l -r #ftp stream tcp nowait root /usr/libexec/ftpd ftpd -l #ftp stream tcp6 nowait root /usr/libexec/ftpd ftpd -l #telnet stream tcp nowait root /usr/libexec/telnetd telnetd #telnet stream tcp6 nowait root /usr/libexec/telnetd telnetd #shell stream tcp nowait root /usr/libexec/rshd rshd #shell stream tcp6 nowait root /usr/libexec/rshd rshd #login stream tcp nowait root /usr/libexec/rlogind rlogind #login stream tcp6 nowait root /usr/libexec/rlogind rlogind #exec stream tcp nowait root /usr/libexec/rexecd rexecd #shell stream tcp6 nowait root /usr/libexec/rshd rshd
This file has the following format:
# sign, it's a comment, and inetd ignores it. You'll note in this example that all the listed services have been commented out. Unless you run the daemon independently of inetd, a request for one of these services will be rejected with the message:
Unable to connect to remote host: Connection refused
internal, which specifies that inetd should perform the function itself.
Older versions of UNIX ran inetd as part of the startup procedure. That isn't always necessary, of course, and for security reasons the default installation of FreeBSD no longer starts it. You can change that by adding the following line to your /etc/rc.conf:
inetd_enable="YES" # Run the network daemon dispatcher (YES/NO).
To enable services in /etc/inetd.conf, it may be enough to remove the comment from the corresponding line. This applies for most the services in the example above. In some cases, though, you may have to perform additional steps. For example, lukemftpd, an alternative ftpd, and nntpd, the Network News Transfer Protocol, are not part of FreeBSD: they're in the Ports Collection. Also, nntpd is intended to run as user use net, which is not in the base system.
The other daemons are not mentioned in /etc/inetd.conf:
The preferred way to run sshd is at system startup. As we'll see, the startup is quite slow, so it's not a good idea to run it from /etc/inetd.conf though it is possible—see the man page if you really want to.
sftp-server is the server for sftp. It gets started from sshd.
httpd, the Apache Web Server, also has quite a long startup phase that makes it impractical to start it from /etc/inetd.conf. Note also that httpd requires a configuration file. We'll look at that on page 455.
By contrast, it's perfectly possible to start rsyncd from inetd. It's not included in the standard /etc/inetd.conf file because it's a port. Yes, so are lukemftpd and nntpd. It's just a little
rsync stream tcp nowait root /usr/local/bin/rsync rsync –daemon
The name rsync is not a typo. rsync and rsyncd are the same thing; it's the --daemon option that makes rsync run as a daemon.
inetd doesn't notice alterations to /etc/inetd.conf automatically. After modifying the file, you must send it a SIGHUP signal:
# killall -HUP inetd
You can write -1 instead of -HUP. This causes inetd to re-read /etc/inetd.conf.
Instead of starting daemons via inetd, you can start them at
Normally you'll run ftpd from inetd, as we saw above. If you want to run it directly, perform the following steps:
echo -n 'starting local daemons:' #put your local stuff here echo " ftpd" ftpd -D
The option -D tells ftpd to run as a daemon. You will possibly want other options as well; see the discussion below.
#) in front of it:
# ftp stream tcp nowait root /usr/libexec/ftpd ftpd -l
inetd to re-read its configuration file:
# killall -1 inetd send a SIGHUP
If you don't perform this step, inetd keeps the ftp port open, and ftpd can't run.
For security reasons, you will probably want to add options such as logging and anonymous ftp. We'll look at how to do that in the next two sections.
Anonymous ftp gives you a couple of security options:
There are a number of preparations for anonymous ftp:
ftp, with the anonymous ftp directory as the home directory and the shell /dev/null. Using /dev/null as the shell makes it impossible to log in as user ftp, but does not Set the ownership of the directories like this:
dr-xr-xr-x 2 ftp ftp 512 Feb 28 12:57 bin drwxrwxrwx 2 ftp ftp 512 Oct 7 05:55 incoming drwxrwxr-x 20 ftp ftp 512 Jun 3 14:03 pub
This enables read access to the pub directory and read-write access to the incoming
d--x--x-- x 20 ftp ftp 512 Jun 314:03 pub
This allows access to the files, but not to the directory, so the
You can ("hard") link the files if you want (and if the directory is on the same file system), but
A number of ftpd options make it easier to control and monitor ftp access:
-l option logs each session, whether successful or not, to syslogd with the facility LOG_FTP. To enable this logging, your /etc/syslog.conf should contain a line like
ftp.* /var/log/ftpd
In addition, the file /var/log/ftpd must exist. If it doesn't, create it with:
# touch /var/log/ftpd
-l option has two levels: if you specify it once, it logs connections only. If you specify it twice, it also lists the files that are transferred.-S option logs all anonymous transfers to the file /var/log/ftpd.-A option.There are a number of other options; see the man page ftpd(8) for further details.
In addition to these options, when a real user establishes a connection, ftpd checks the user's shell. If it is not listed in /etc/shells, ftpd will deny the connection. This can be useful if you don't want specific users to access the system: give them a different shell, such as /usr/bin/sh instead of /bin/sh, and ensure that /usr/bin/sh is not in /etc/shells.
The format of the log files is a little unusual. You'll see things like:
Oct 12 16:32:04 freebie ftpd[8691]: ANONYMOUS FTP LOGIN FROM adam.adonai.net, leec@a donainet Oct 12 18:33:32 freebie ftpd[9007]: connection from gateway.smith.net.au Oct 12 18:33:37 freebie ftpd[9007]: ANONYMOUS FTP LOGIN FROM gateway.smith.net.au, m ike Oct 12 21:36:28 freebie ftpd[9369]: connection from grisu.bik-gmbh.de Oct 12 21:36:29 freebie ftpd[9369]: ANONYMOUS FTP LOGIN FROM grisu.bik-gmbh.de, harv est@ Oct 12 21:36:37 1997!harvest@!grisu.bik-gmbh.de!/pub/cfbsd/README!9228!1 Oct 12 21:37:05 freebie ftpd[9371]: connection from grisu.bik-gmbh.de Oct 12 21:37:06 freebie ftpd[9371]: ANONYMOUS FTP LOGIN FROM grisu.bik-gmbh.de, harv est@ Oct 13 09:38:19 freebie ftpd[13514]: connection from 151.197.101.46 Oct 13 09:38:21 freebie ftpd[13514]: ANONYMOUS FTP LOGIN FROM 151.197.101.46, bmc@ho vercraft.willscreek.com Oct 13 09:38:58 1997!bmc@hovercraft.willscreek.com!151.197.101.46!/pub/cfbsd/dear-re viewer!8890!1 Oct 13 09:41:42 1997!bmc@hovercraft.willscreek.com!151.197.101.46!/pub/cfbsd/txt/26-netdebug.txt.gz!12188!1 Oct 13 09:42:05 1997!bmc@hovercraft.willscreek.com!151.197.101.46!/pub/cfbsd/txt/C-p ackages.txt.gz!37951!1 Oct 13 09:59:07 freebie ftpd[14117]: connection from 151.197.101.46 Oct 13 09:59:08 freebie ftpd[14117]: ANONYMOUS FTP LOGIN FROM 151.197.101.46, bmc@ho vercraft.willscreek.com Oct 13 09:59:24 1997!bmc@hovercraft.willscreek.com!151.197.101.46!/pub/cfbsd/txt/D-b iblio.txt.gz!1815!1
This log excerpt shows three kinds of message:
connection from occur when an ftp connection is made. They don't mean that any permission to access has been given. These messages are logged by the -l option.ANONYMOUS FTP LOGIN messages show that somebody has logged in anonymously. The name follows, not always in the required username format. The standard ftpd does not enforce this requirement; you may find something that does in the Ports Collection. These messages are logged by the -S option.! marks show files being transferred. The ! marks delimit the fields, which are:
Normally you start sshd from the system configuration file /etc/rc.conf:
sshd_enable="YES" # Enable sshd
That's all you need to do for sshd. You can also start it simply with:
#sshd
sshd reads a configuration file /etc/ssh/sshd_config. Like its companion /etc/ssh/ssh_config, it contains mainly commented-out lines showing the default values. Most of them don't require change, but the following entries may be of interest:
Protocol states which ssh protocols to use, and in which order. By default, sshd tries protocol 2 first, and falls back to protocol 1 if protocol 2 fails. You might consider setting it to use only protocol 2.PermitRootLogin is set to yes, you can log in as root via ssh. Normally it's disabled.PasswordAuthentication to no if you want all access to be via key exchange (see page 420 for more details).Subsystem sftp /usr/libexec/sftp-server
It should be present by default.
As we've seen, rsyncd is just another name for rsync. You don't need to do any specific configuration to start it: it gets started from sshd, so all you need to do is to ensure that sshd gets started.
Starting rsyncd isn't enough, though: it needs configuration. Create a file /usr/local/etc/rsyncd.conf with contents something like this:
motd file = /usr/local/etc/rsyncd.txt
log file = /var/log/rsyncd.log
transfer logging = true
[groggy]
path = /home/grog/public_html
uid = grog
read only = yes
list = yes
comment = Greg's web pages
hosts allow = 223.147.37.0/24
[tivo]
path = /var/tivo
uid = grog
read only = no
list = yes
comment = TiVo staging area
hosts allow = tivo.example.org
This is the configuration file used in the server examples in Chapter 24. It consists of two parts: a global part at the beginning, with settings that apply to all modules, and one or more module parts describing files that the server will supply.
The global options here specify the motd file, a file whose contents are printed when you list modules (the ''be gentle'' message in the examples), and that transfers should be logged to /var/log/rsyncd.log. The log output looks something like this:
2002/10/24 13:31:49 [16398] send presto.example.org [192.109.197.74] groggy () slash dot/topicscience.gif 1083 2002/10/24 13:31:49 [16398] send presto.example.org [192.109.197.74] groggy () slash dot/topicsecurity.gif 3034 2002/10/24 13:31:49 [16398] send presto.example.org [192.109.197.74] groggy () slash dot/topictv.jpg 951 2002/10/24 13:31:49 [16398] send presto.example.org [192.109.197.74] groggy () slide .pdf 40470 2002/10/24 13:31:49 [16398] send presto.example.org [192.109.197.74] groggy () stock whip.html 1602
The next part of the configuration file describes modules, directory hierarchies that rsyncd makes available. If you're used to Microsoft-style configuration files, this will seem relatively familiar. The module names are []), and they don't have to have any relationship with the name of the directory. In this case we have two modules. Both have a comment, a descriptive text printed out when you list the modules, and both allow listing the name of the module (list = yes). In addition:
groggy makes available the directory /home/grog/public_html, my web pages, for read-only access. rsyncd accesses the module as user grog. Any host on the 256 address block starting with 223.147.37.0 can access the data.grog.There are a large number of other options for rsyncd, but this example shows the most important ones. See the man page rsyncd.conf(5) for more information.
FreeBSD is a system of choice for running web servers, so it's not surprising that a large number are available. Probably the most popular is apache, which is available in the Ports Collection. Install with:
# cd /usr/ports/www/apache13 # make install
In future versions, the name apache13 will change. Apache comes with a lot of documentation in HTML format (of course), which is installed in /usr/local/share/doc/apache/manual. You might find it useful to put a
# cd /usr/local/www/data # ln -s /usr/local/share/doc/apache/manual apachedoc
After this, you can access the documentation at (for example) http://www.example.org/apachedoc/.
The Apache port uses the following directories:
DocumentRoot entry in the configuration file.The apache configuration file is /usr/local/etc/apache/httpd.conf. Older versions of apache also used the files /usr/local/etc/apache/access.conf and /usr/local/etc/apache/srm.conf. The division between these three files was relatively
Probably the best way to understand httpd.conf is to read through it. It's pretty long and contains a large number of comments. Most entries can be left the way there are, so we won't list the entire file here: instead we'll look at the parameters that may need change. We'll look at the system-wide features in the following list, and host-related features in the next section.
ServerType states whether you start it from inetd or standalone (the default). It's not a good idea to start httpd from inetd, so you should leave this entry ServerRoot claims to be the path to the configuration files, but in fact the files are stored in the ScoreBoardFile suggest that you should check to see if the system creates one. Don't bother: FreeBSD doesn't create this file, and you don't need to worry about it.HTTP/1.1 draft, allows persistent connections. These long-lived HTTP sessions allow multiple requests to be sent over the same TCP connection, and in some cases have been shown to result in an almost 50% MinSpareServers, MaxSpareServers, StartServers, Max-Clients and MaxRequestsPerChild are used for server tuning. The default values should work initially, but if you have a lot of Web traffic, you should consider changing them.modules. A lot of apache functionality is optional, and you include it by including a module. We'll look at this in more detail below.ProxyRequests allows Apache to function as a proxy server. We'll look at this in more detail below.Cache apply only to proxy servers, so we'll look at them below as well.Directorylndex is a list of names that httpd recognizes as the main page ("index") in the directory. Traditionally it's index.html. This is the means by which httpd changes a directory name into an index. It searches for the names in the order specified. For example, if you're using PHP, Directorylndex gets set to the string index.php index.php3 index.html, and that's the sequence in which it looks for a page.The file ends with a commented out VirtualHost section. We'll look at it in detail in the next section, along with a number of parameters that appear elsewhere in the configuration file, but that relate to virtual hosts.
Running and maintaining a web server is enough work that you might want to use the same server to host several sets of web pages, for example for a number of different organizations. apache calls this feature virtual hosts, and it offers a lot of support for them.
There's a good reason to keep the "main" server information: it serves as defaults for all virtual hosts, which can make the job of adding a virtual host a lot easier.
Consider your setup at http://example.org: you may run your own web pages and also a set of pages for http://biguser.com (see page 310). To do this, you add the following section to /usr/local/etc/apache/httpd.conf:
<VirtualHost *> ServerAdmin grog@example.org DocumentRoot /usr/local/www/biguser Where we put the web pages ServerName www.biguser.com the name that the server will claim to be ServerAlias biguser.com alternative server name ErrorLog /var/log/biguser/error_log TransferLog /var/log/biguser/access_log Options +FollowSymLinks Options +SymLinksIfOwnerMatch </VirtualHost>
If you look at the VirtualHost definition. They are the corresponding parameters for the "main" web server. They have the same meaning, so we'll look at them here.
ServerAdmin is the mail ID of the system administrator. For the main server, it's set to you@your.address, which obviously needs to be changed. You don't necessarily need a ServerAdmin for each virtual domain; that depends on how you run the system.<Directory /> Options FollowSymLinks AllowOverride None </Directory>
The / in the first line indicates the local directory to which these settings should apply. For once, this is really the DocumentRoot: they're system-wide defaults, and though you don't have to worry about apache playing around in your root file system, that's the only directory of which all other directories are Options directive ensures that the server can follow AllowOverride directive in the discussion of the .htaccess file below.
There's a separate entry for the
<Directory "/usr/local/www/data"> Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny Allow from all </Directory>
In this case, we have two additional options:
Indexes allows httpd to display the contents of a directory if no index file, with a name defined in DirectoryIndex, is present. Without this option, if there is no index file present, you will not be able to access the directory at all.MultiViews allows content-based Note that if you change the name of the default data directory, you should also change the name on the Directory invocation.
We'll look at the remaining entries in more detail when we see them again in the discussion of the .htaccess file.
ServerName. For example, www.example.org is a CNAME for freebie.example.org (see page 370), and if you don't set this value, clients will access www.example.org, but the server will return the name freebie.example.org.Options +SymLinksIfOwnerMatch limits following Options directive specifies all the options: it doesn't merge the + sign indicates that the option specified should be added to the defaults.After restarting with these parameters. If you don't define a virtual host, the server will access the main web pages (defined by the main DocumentRoot in entry /usr/local/etc/apache/access.conf).
httpd logs accesses and errors to the files you specify. It's worth understanding what's inside them. The following example shows five log entries. Normally each entry is all on a very long line.
p50859b17.dip.t-dialin.net - - name of system, more [01/Nov/2002:07:06:12 +1030] date of access "GET /Images/yaoipower.jpeg HTTP/1.1" HTML command 200 status (OK) 19365 length of data transfer aceproxy3.acenet.net.au - - [01/Nov/2002:07:35:34 +1030] "GET /Images/randomgal.big.jpeg HTTP/1.0" 304 - status (cached) 218.24.24.27 - - system without reverse DNS [01/Nov/2002:07:39:55 +1030] "GET /scripts/root.exe?/c+dir HTTP/1.0" looking for an invalid file 404 284 status (not found) 218.24.24.27 - - [01/Nov/2002:07:39:56 +1030] "GET /MSADC/root.exe?/c+dir HTTP/1.0" 404 282 218.24.24.27 - - [01/Nov/2002:07:39:56 +1030] "GET /c/winnt/system32/cmd.exe?/c+dir HTTP/1.0" 404 292 218.24.24.27 - - [01/Nov/2002:07:40:00 +1030] "GET /_vti_bin/..%255c../..%255c../..%255c../winnt/system32/cmd.exe?/c+dir HTTP/1.0" 404 323
The fields in the log file are separated by blanks, so empty entries are replaced by a - character. In this example, the second and third fields are always empty. They're used for identity checks and authorization.
To get the names of the clients, you need to specify the HostnameLookups on directive. This requires a DNS lookup for every access, which can be relatively slow.
Although we specified hostname lookups, the last four entries don't have any name: the system doesn't have reverse DNS. They come from a Microsoft machine
Sometimes you want to restrict access to a web server, either for specific directories or for the web site as a whole. apache has a number of options to limit access. One possibility is to set options in /usr/local/etc/apache/httpd.conf to cover an individual host, but this is seldom useful. It's more likely that you will want to restrict access to specific directories, and it's easier to do that in the file .htaccess in the same directory.
For apache to even look at .htaccess, you need to change the configuration file, however: by default, it disables the use of .htaccess a together, as we saw above:
<Directory /> Options FollowSymLinks AllowOverride None </Directory>
For it to work, you'll have to change the AllowOverride parameter to some other value. There are five categories of entries that you can allow in .htaccess files:
AuthConfig allows .htaccess to include authorization directives.FileInfo allows the use of directives controlling document types.Indexes allows the use of directives controlling directory indexing.Limit allows the use of directives controlling host access.Options allows the use of directives controlling specific directory features.You can find more details in /usr/local/share/doc/apache/manual/mod/core.html.
The most common use of the .htaccess is to require that users authorize themselves before accessing a directory. In this case, the browser will pop up a window like this:
(рис 25.1)
To achieve this, add something like this to your .htaccess file:
AuthType Basic AuthName grog AuthDBUserFile /usr/local/etc/apache/passwd Require valid-user
This method is similar to normal login authentication. You need a password file, which you can create and update with dbmmanage:
# dbmmanage /usr/local/etc/apache/passwd adduser grog New password: Re-type new password: User grog added with password encrypted to OzREW8Xx5hUAs using crypt # dbmmanage /usr/local/etc/apache/passwd adduser guest New password: Re-type new password: User guest added with password encrypted to hFCYwd23ftHE6 using crypt
This adds passwords for users grog and guest. The AuthName suggests a name to authenticate, but Require valid-user states that it can be any user. Even if you don't care which user logs in, you need to specify an AuthName line. If you do insist that only user grog can log in, you can write:
Require user grog
This will fail the authentication for any other user. You can also specify a list of users or groups. For example, you might add the following line:
AuthGroupFile /usr/local/etc/apache/group Require group bigshots
/usr/local/etc/apache/group might then contain:
bigshots: davidb davidp gordon grog liz malcolm
This will allow any of the users specified on this line to access the directory.
apache offers a large quantity of optional functionality, which it provides in the form of dynamically LoadModule and tells httpd which dynamic modules to load. The order is important; don't change it.
Apache is capable of operating as a
Unfortunately, by default the current version of Apache does not support proxy servers. You need to rebuild the package manually after enabling it in the configuration file. See the file INSTALL in the port build directory for more details. This file will be present after building Apache from source, and it will have a name like /usr/ports/www/apache13/work/apache1.3.23/src/INSTALL.Inaddition to ProxyRequests to On to enable the
One reason for enabling the
The Cache parameters are commented out by default. If you uncomment them, you should uncomment them all except possibly NoCache. When setting these values, change the name of the directory CacheRoot. A good name might be /usr/local/www/proxy.
When you install apache, it
# apachectl start start httpd # apachectl stop stop httpd # apachectl restart restart httpd, or start if not running # apachectl graceful restart httpd "gracefully," or start if not running # apachectl configtest do a configuration syntax test
The difference between a normal and a "graceful" restart is that the graceful restart waits for existing connections to complete before restarting the individual
A number of processes are needed to provide NFS server functionality:
monitoring service.
In addition:
A number of security
NFS was developed at a time when users were relatively trusted. precautions are not overly
file system options systems
systems is a list of systems allowed to mount the file system. The only required field is the name of the file system, but if you're on the Internet, you should at least limit the number of systems that can mount your file systems. By default any system on the Net can mount your file systems.
There are a number of options. Here are the more important ones:
-maproot option describes how to treat root. By default, root does not have special privileges on the nobody, which is user 65534 (or -2). You can change this with the -maproot option. For example, to map root to the real root user for a specific file system, you would add -maproot=0 to the line describing the file system.-mapall option maps the user IDs of other users. This is relatively uncommon. See the man page exports(5) for more details.-ro option restricts access to read-only.–network option restricts the access to systems on the specified network.-alldirs option allows remote clients to mount any directory in the file system directly. Without this option, remote clients can only mount the -alldirs can be of use during the discussion of diskless booting on page 543.If you come from a System V background, you'll notice that the mechanism is different. /etc/exports corresponds in concept roughly to System V's /etc/dfs/dfstab file, except that the share statement does not exist.
To grant access to a file system, it's not enough to change the contents of /etc/exports: you also need to tell mountd that you have done so. You do this by the relatively common method of sending a SIGHUP) to mountd:
# killall -HUP mountd
A typical /etc/exports for presto might be:
/ -maproot=0 presto bumble wait gw /usr -maproot=0 -alldirs -network 223.147.37.0
This allows root access to both file systems. Only the trusted systems presto, bumble, wait and gw are allowed to access the root file system, whereas any system on the local network may access /usr.
BSD UNIX and the Internet grew up together, but it took other vendors a long time to accept the Internet Protocols. In that time, a number of other protocols arose. We've already mentioned X.25 and SNA, currently both not supported by FreeBSD. The protocols that grew up in the DOS world are more widespread, in particular Novell's IPX and Microsoft's Common Internet File System, or CIFS. CIFS was previously known as SMB (Server Message Block).
IPX support is relatively rudimentary. FreeBSD includes an IPX routing daemon, IPXrouted. See the man page IPXrouted(8) for further information. IPX is going out of use, so it's unlikely that support for it will improve. By contrast, Microsoft's
you can get even more information, including support and a
Samba includes a number of programs, most of which we don't touch on here. The ones we look at are:
Install Samba from the port:
# cd /usr/ports/net/samba # make install
This operation installs the Samba binaries in /usr/local/bin, the standard location for additional binaries on a BSD system, and the daemons smbd and nmbd in /usr/local/sbin. These locations are appropriate for FreeBSD, but they are not the locations that the Samba documentation recommends. It also installs the man pages in /usr/local/man, where the man program can find them. Finally, it installs a sample configuration file in /usr/local/etc/smb.conf.default. We'll look at how to configure Samba below.
There are a number of security
root. smbd should be executable by all. Don't make it setuid. If an individual user runs it, it runs with their permissions.root, since they may contain sensitive information.root can change it.
The Samba documentation recommends setting the directory readable and writeable only by root. Depending on what other configuration files you have in /etc/local/etc, this could cause problems.
The main component of Samba is smbd, the SMB daemon. In addition, you need the Samba name daemon, nmbd, which supplies NetBIOS name services for Samba. smbd requires a configuration file, which we'll look at below, while you don't normally need one for nmbd. By default, nmbd maps DNS host names (without the domain part) to NetBIOS names, though it can perform other functions if you need them. In this chapter we'll assume the nmbd(8) for other possibilities.
You have two choices of how to run smbd and nmbd: you can start them at
When you install Samba from the Ports Collection, it installs a file /usr/local/etc/rc.d/samba.sh.sample .You just need to rename it to /usr/local/etc/rc.d/samba.sh. As the name suggests, it's a shell script. You can modify it if necessary, but it's usually not necessary.
The man page for smbd gives a number of parameters to specify the configuration file and the log file. As long as you stick to the specified file names, you shouldn't need to change anything: by default, smbd looks for the configuration file at /usr/local/etc/smb.conf, and this file contains the names of the other files.
To run the daemons from inetd,
# in front. Remove the # to show the lines as they are here. If your /etc/inetd.conf doesn't contain these lines, add them.
netbios-ssn stream tcp nowait root /usr/local/sbin/smbd smbd netbios-ns dgram udp wait root /usr/local/sbin/nmbd nmbd swat stream tcp nowait/400 root /usr/local/sbin/swat swat
swat is an administration tool that we don't discuss here.
# killall -1 inetd send a SIGHUP
The Samba configuration file describes the services that the daemon offers. The port installs a sample configuration file in /usr/local/etc/smb.conf.default. You can use it as the basis of your own configuration file, which must be called /usr/local/etc/smb.conf: simply copy the file, and then edit it as described below.
The configuration file is divided into sections identified by a label in [global], [homes] and [printers], all of which are optional. We look at them in the following sections.
As the name suggests, the [global] section defines parameters that either apply to the server as a whole, or that are defaults for the other services. The interesting ones for us are:
workgroup parameter defines the Microsoft workgroup to which this server belongs. Set it to match the Microsoft environment. In these examples, we'll assume:
workgroup = EXAMPLE
printing entry specifies what kind of printer support Samba provides. Current versions of Samba support CUPS. If you are using CUPS (not described in this book), you don't need to do anything. Otherwise set:
printcap name = /etc/printcap printing = bsd
guest account is the account (in UNIX terms: user ID) to use if no password is supplied. You probably want to define a guest account, since many Microsoft clients don't use user IDs. Ensure that the privileges are set appropriately. Alternatively, alter the parameter to point to an existing user.encrypt passwords to yes.dns proxy to yes.log file = /var/log/samba.log.%m
socket options is hardly mentioned in the documentation, but it's very important: many Microsoft implementations of TCP/IP are TCP_NODELAY and IPTOS_LOWDELAY, which can speed up the The [homes] section allows clients to connect to their home directories without needing an entry in the configuration file. If this section is present, and an incoming request specifies a service that is not defined in the configuration file, Samba checks if it matches a user ID. If it does, and if the specified password is correct, Samba creates a service that supplies the user's home directory.
The following options are of interest in the [homes] section:
writeable can be yes or no, and specifies whether the user is allowed to write to the directory.create mode specifies the permission bits (in public specifies whether other users are allowed access to this directory. In combination with a guest user, this can be a serious security liability.The [printers] section describes printing services. It doesn't need the names of the printers: if it doesn't find the specified service, either in the configuration file or in the [homes] section, if it exists, it looks for them in the /etc/printcap file.
The Samba documentation claims that Samba can recognize BSD printing system automatically, but this is not always correct. Ensure that you have the following entries:
printing = bsd in the [global] sectionW print command = lpr -r -P'%p' '%s' in the [printers] sectionW
Note the printable option in the [printers] section: this is the option that distinguishes between printers ("yes")and no").
Samba takes any section name except for [global], [homes] or [printers] as the definition of a service. A typical example might be:
[ftp] comment = ftp server file area path = /var/spool/ftp/pub read only = yes public = yes write list = grog
This entry defines access to the anonymous ftp section. Anybody can read it, but only user grog can write to it.
Samba uses a separate password file, /usr/local/private/secrets.tdb. To set up users, use the smbpasswd command, which copies the information from the system password file:
# smbpasswd -a grog New SMB password: Retype new SMB password: as usual, no echo Password changed for user grog.
Once you have performed the steps described above, you can proceed to test the installation. First, run testparm to check the correctness of the configuration file:
$ testparm Load smb config files from /usr/local/etc/smb.conf Processing section "[homes]" Processing section "[printers]" Processing section "[ftp]" Processing section "[src]" Processing section "[grog]" Loaded services file OK. Press enter to see a dump of your service definitions Press Enter Global parameters: lots of information which could be of use in debugging [homes] comment = Home Directories read only = No [printers] comment = All Printers path = /var/spool/samba guest ok = Yes printable = Yes browseable = No [ftp] comment = ftp server file area path = /var/spool/ftp/pub write list = grog guest ok = Yes [grog] path = /home/grog valid users = grog read only = No
As you see, testparm spells out all the parameters that have been created, whether explicitly or by default. If you run into problems, this is the first place to which to return.
Next, check that you can log in with smbclient. If you're running the servers as daemons, start them now. If you're starting them from inetd, you don't need to do anything.
$ smbclient -L freebie -U grog added interface ip=223.147.37.1 bcast=223.147.37.255 nmask=255.255.255.0 Password: as usual, no echo Domain=[EXAMPLE] OS=[Unix] Server=[Samba 2.2.7a] Sharename Type Comment --------- ---- ------- homes Disk Home Directories ftp Disk ftp server file area grog Disk IPC$ IPC IPC Service (Samba Server) ADMIN$ Disk IPC Service (Samba Server) Server Comment ------ ------- FREEBIE Samba Server PRESTO Samba Server Workgroup Master --------- ------ EXAMPLE PRESTO
If you get this far, your password authentication is working. Finally, try to access the shares. Samba services are specified in Microsoft format: \\system\service. To make this worse, UNIX interprets the \ character specially, so you would need to repeat the character. For example, to access the ftp service on freebie, you would have to enter \\\\freebie\\ftp. Fortunately, smbclient understands UNIX-like names, so you can write //freebie/ftp instead.
To test, start smbclient from another system:
$ smbclient //freebie/ftp -U grog added interface ip=223.147.37.1 bcast=223.147.37.255 nmask=255.255.255.0 Password: as usual, no echo Domain=[EXAMPLE] OS=[Unix] Server=[Samba 2.2.7a] smb: \> ls . DR 0 Wed Jan 29 12:06:29 2003 .. D 0 Sat Oct 26 10:36:29 2002 instant-workstation-1.0.tar.gz 9952 Mon Mar 19 11:49:01 2001 xtset-1.0.tar.gz 4239 Mon Aug 5 16:44:14 2002 gpart-0.1h.tbz.tgz 27112 Tue Aug 27 10:07:59 2002
If you get this far, Samba is working. The next step is to attach to the services from the Microsoft machines. That's not a topic for this book. Note, however, that Samba only works with TCP/IP transport, not with NetBEUI.
You can display the status of Samba connections with smbstatus. For example,
$ smbstatus Samba version 2.2.7a Service uid gid pid machine -------------------------------------- ftp grog example 37390 freebie (223.147.37.1) Mon Mar 31 13:48:13 2003 No locked files
In the previous chapter, we saw how to use clients to access other systems. This is only half the picture, of course. At the other end of the link, we need servers to provide this service. For each client, there is a server (a daemon) whose name is usually derived from the client name by adding a d to it:
| Client | Server |
|---|---|
| ssh | sshd |
| telnet | telnetd |
| ftp | |
| rsync | rsyncd |
| (browser) | httpd |
| (NFS) | nfsd |
In addition to these servers, we look at a few others in other chapters:
Some servers don’t need any configuration, and about all you need to do is to start them. Others, like web servers, can be very complicated. None of the complication is related to FreeBSD. For example, the issues involved in configuring apache are the same whether you run it with FreeBSD,
If you look at /etc/services, you'll find that there are over 800 services available, most of which are only supported on a small number of machines. It's not always the best idea to start up a daemon for every possible service you may want to offer. IP supplies an alternative: inetd, the Internet daemon, sometimes called a super-server, which listens on multiple ports. When a request arrives on a specific port, inetd starts a daemon specific to the port. For example, FreeBSD supports anonymous ftp, but most people don't receive enough requests to warrant having the ftp daemon, ftpd, running all the time. Instead, inetd starts an ftpd when a request comes in on port 21.
At startup, inetd reads a configuration file /etc/inetd.conf to determine which ports to monitor and what to do when a message comes in. Here's an excerpt:
#$FreeBSD: src/etc/inetd.conf,v 1.58 2002/08/09 17:34:13 gordon Exp $ # #Internet server configuration database # #ftp stream tcp nowait root /usr/libexec/lukemftpd ftpd -l -r #ftp stream tcp nowait root /usr/libexec/ftpd ftpd -l #ftp stream tcp6 nowait root /usr/libexec/ftpd ftpd -l #telnet stream tcp nowait root /usr/libexec/telnetd telnetd #telnet stream tcp6 nowait root /usr/libexec/telnetd telnetd #shell stream tcp nowait root /usr/libexec/rshd rshd #shell stream tcp6 nowait root /usr/libexec/rshd rshd #login stream tcp nowait root /usr/libexec/rlogind rlogind #login stream tcp6 nowait root /usr/libexec/rlogind rlogind #exec stream tcp nowait root /usr/libexec/rexecd rexecd #shell stream tcp6 nowait root /usr/libexec/rshd rshd
This file has the following format:
# sign, it's a comment, and inetd ignores it. You'll note in this example that all the listed services have been commented out. Unless you run the daemon independently of inetd, a request for one of these services will be rejected with the message:
Unable to connect to remote host: Connection refused
internal, which specifies that inetd should perform the function itself.
Older versions of UNIX ran inetd as part of the startup procedure. That isn't always necessary, of course, and for security reasons the default installation of FreeBSD no longer starts it. You can change that by adding the following line to your /etc/rc.conf:
inetd_enable="YES" # Run the network daemon dispatcher (YES/NO).
To enable services in /etc/inetd.conf, it may be enough to remove the comment from the corresponding line. This applies for most the services in the example above. In some cases, though, you may have to perform additional steps. For example, lukemftpd, an alternative ftpd, and nntpd, the Network News Transfer Protocol, are not part of FreeBSD: they're in the Ports Collection. Also, nntpd is intended to run as user use net, which is not in the base system.
The other daemons are not mentioned in /etc/inetd.conf:
The preferred way to run sshd is at system startup. As we'll see, the startup is quite slow, so it's not a good idea to run it from /etc/inetd.conf though it is possible—see the man page if you really want to.
sftp-server is the server for sftp. It gets started from sshd.
httpd, the Apache Web Server, also has quite a long startup phase that makes it impractical to start it from /etc/inetd.conf. Note also that httpd requires a configuration file. We'll look at that on page 455.
By contrast, it's perfectly possible to start rsyncd from inetd. It's not included in the standard /etc/inetd.conf file because it's a port. Yes, so are lukemftpd and nntpd. It's just a little
rsync stream tcp nowait root /usr/local/bin/rsync rsync –daemon
The name rsync is not a typo. rsync and rsyncd are the same thing; it's the --daemon option that makes rsync run as a daemon.
inetd doesn't notice alterations to /etc/inetd.conf automatically. After modifying the file, you must send it a SIGHUP signal:
# killall -HUP inetd
You can write -1 instead of -HUP. This causes inetd to re-read /etc/inetd.conf.
Instead of starting daemons via inetd, you can start them at
Normally you'll run ftpd from inetd, as we saw above. If you want to run it directly, perform the following steps:
echo -n 'starting local daemons:' #put your local stuff here echo " ftpd" ftpd -D
The option -D tells ftpd to run as a daemon. You will possibly want other options as well; see the discussion below.
#) in front of it:
# ftp stream tcp nowait root /usr/libexec/ftpd ftpd -l
inetd to re-read its configuration file:
# killall -1 inetd send a SIGHUP
If you don't perform this step, inetd keeps the ftp port open, and ftpd can't run.
For security reasons, you will probably want to add options such as logging and anonymous ftp. We'll look at how to do that in the next two sections.
Anonymous ftp gives you a couple of security options:
There are a number of preparations for anonymous ftp:
ftp, with the anonymous ftp directory as the home directory and the shell /dev/null. Using /dev/null as the shell makes it impossible to log in as user ftp, but does not Set the ownership of the directories like this:
dr-xr-xr-x 2 ftp ftp 512 Feb 28 12:57 bin drwxrwxrwx 2 ftp ftp 512 Oct 7 05:55 incoming drwxrwxr-x 20 ftp ftp 512 Jun 3 14:03 pub
This enables read access to the pub directory and read-write access to the incoming
d--x--x-- x 20 ftp ftp 512 Jun 314:03 pub
This allows access to the files, but not to the directory, so the
You can ("hard") link the files if you want (and if the directory is on the same file system), but
A number of ftpd options make it easier to control and monitor ftp access:
-l option logs each session, whether successful or not, to syslogd with the facility LOG_FTP. To enable this logging, your /etc/syslog.conf should contain a line like
ftp.* /var/log/ftpd
In addition, the file /var/log/ftpd must exist. If it doesn't, create it with:
# touch /var/log/ftpd
-l option has two levels: if you specify it once, it logs connections only. If you specify it twice, it also lists the files that are transferred.-S option logs all anonymous transfers to the file /var/log/ftpd.-A option.There are a number of other options; see the man page ftpd(8) for further details.
In addition to these options, when a real user establishes a connection, ftpd checks the user's shell. If it is not listed in /etc/shells, ftpd will deny the connection. This can be useful if you don't want specific users to access the system: give them a different shell, such as /usr/bin/sh instead of /bin/sh, and ensure that /usr/bin/sh is not in /etc/shells.
The format of the log files is a little unusual. You'll see things like:
Oct 12 16:32:04 freebie ftpd[8691]: ANONYMOUS FTP LOGIN FROM adam.adonai.net, leec@a donainet Oct 12 18:33:32 freebie ftpd[9007]: connection from gateway.smith.net.au Oct 12 18:33:37 freebie ftpd[9007]: ANONYMOUS FTP LOGIN FROM gateway.smith.net.au, m ike Oct 12 21:36:28 freebie ftpd[9369]: connection from grisu.bik-gmbh.de Oct 12 21:36:29 freebie ftpd[9369]: ANONYMOUS FTP LOGIN FROM grisu.bik-gmbh.de, harv est@ Oct 12 21:36:37 1997!harvest@!grisu.bik-gmbh.de!/pub/cfbsd/README!9228!1 Oct 12 21:37:05 freebie ftpd[9371]: connection from grisu.bik-gmbh.de Oct 12 21:37:06 freebie ftpd[9371]: ANONYMOUS FTP LOGIN FROM grisu.bik-gmbh.de, harv est@ Oct 13 09:38:19 freebie ftpd[13514]: connection from 151.197.101.46 Oct 13 09:38:21 freebie ftpd[13514]: ANONYMOUS FTP LOGIN FROM 151.197.101.46, bmc@ho vercraft.willscreek.com Oct 13 09:38:58 1997!bmc@hovercraft.willscreek.com!151.197.101.46!/pub/cfbsd/dear-re viewer!8890!1 Oct 13 09:41:42 1997!bmc@hovercraft.willscreek.com!151.197.101.46!/pub/cfbsd/txt/26-netdebug.txt.gz!12188!1 Oct 13 09:42:05 1997!bmc@hovercraft.willscreek.com!151.197.101.46!/pub/cfbsd/txt/C-p ackages.txt.gz!37951!1 Oct 13 09:59:07 freebie ftpd[14117]: connection from 151.197.101.46 Oct 13 09:59:08 freebie ftpd[14117]: ANONYMOUS FTP LOGIN FROM 151.197.101.46, bmc@ho vercraft.willscreek.com Oct 13 09:59:24 1997!bmc@hovercraft.willscreek.com!151.197.101.46!/pub/cfbsd/txt/D-b iblio.txt.gz!1815!1
This log excerpt shows three kinds of message:
connection from occur when an ftp connection is made. They don't mean that any permission to access has been given. These messages are logged by the -l option.ANONYMOUS FTP LOGIN messages show that somebody has logged in anonymously. The name follows, not always in the required username format. The standard ftpd does not enforce this requirement; you may find something that does in the Ports Collection. These messages are logged by the -S option.! marks show files being transferred. The ! marks delimit the fields, which are:
Normally you start sshd from the system configuration file /etc/rc.conf:
sshd_enable="YES" # Enable sshd
That's all you need to do for sshd. You can also start it simply with:
#sshd
sshd reads a configuration file /etc/ssh/sshd_config. Like its companion /etc/ssh/ssh_config, it contains mainly commented-out lines showing the default values. Most of them don't require change, but the following entries may be of interest:
Protocol states which ssh protocols to use, and in which order. By default, sshd tries protocol 2 first, and falls back to protocol 1 if protocol 2 fails. You might consider setting it to use only protocol 2.PermitRootLogin is set to yes, you can log in as root via ssh. Normally it's disabled.PasswordAuthentication to no if you want all access to be via key exchange (see page 420 for more details).Subsystem sftp /usr/libexec/sftp-server
It should be present by default.
As we've seen, rsyncd is just another name for rsync. You don't need to do any specific configuration to start it: it gets started from sshd, so all you need to do is to ensure that sshd gets started.
Starting rsyncd isn't enough, though: it needs configuration. Create a file /usr/local/etc/rsyncd.conf with contents something like this:
motd file = /usr/local/etc/rsyncd.txt
log file = /var/log/rsyncd.log
transfer logging = true
[groggy]
path = /home/grog/public_html
uid = grog
read only = yes
list = yes
comment = Greg's web pages
hosts allow = 223.147.37.0/24
[tivo]
path = /var/tivo
uid = grog
read only = no
list = yes
comment = TiVo staging area
hosts allow = tivo.example.org
This is the configuration file used in the server examples in Chapter 24. It consists of two parts: a global part at the beginning, with settings that apply to all modules, and one or more module parts describing files that the server will supply.
The global options here specify the motd file, a file whose contents are printed when you list modules (the ''be gentle'' message in the examples), and that transfers should be logged to /var/log/rsyncd.log. The log output looks something like this:
2002/10/24 13:31:49 [16398] send presto.example.org [192.109.197.74] groggy () slash dot/topicscience.gif 1083 2002/10/24 13:31:49 [16398] send presto.example.org [192.109.197.74] groggy () slash dot/topicsecurity.gif 3034 2002/10/24 13:31:49 [16398] send presto.example.org [192.109.197.74] groggy () slash dot/topictv.jpg 951 2002/10/24 13:31:49 [16398] send presto.example.org [192.109.197.74] groggy () slide .pdf 40470 2002/10/24 13:31:49 [16398] send presto.example.org [192.109.197.74] groggy () stock whip.html 1602
The next part of the configuration file describes modules, directory hierarchies that rsyncd makes available. If you're used to Microsoft-style configuration files, this will seem relatively familiar. The module names are []), and they don't have to have any relationship with the name of the directory. In this case we have two modules. Both have a comment, a descriptive text printed out when you list the modules, and both allow listing the name of the module (list = yes). In addition:
groggy makes available the directory /home/grog/public_html, my web pages, for read-only access. rsyncd accesses the module as user grog. Any host on the 256 address block starting with 223.147.37.0 can access the data.grog.There are a large number of other options for rsyncd, but this example shows the most important ones. See the man page rsyncd.conf(5) for more information.
FreeBSD is a system of choice for running web servers, so it's not surprising that a large number are available. Probably the most popular is apache, which is available in the Ports Collection. Install with:
# cd /usr/ports/www/apache13 # make install
In future versions, the name apache13 will change. Apache comes with a lot of documentation in HTML format (of course), which is installed in /usr/local/share/doc/apache/manual. You might find it useful to put a
# cd /usr/local/www/data # ln -s /usr/local/share/doc/apache/manual apachedoc
After this, you can access the documentation at (for example) http://www.example.org/apachedoc/.
The Apache port uses the following directories:
DocumentRoot entry in the configuration file.The apache configuration file is /usr/local/etc/apache/httpd.conf. Older versions of apache also used the files /usr/local/etc/apache/access.conf and /usr/local/etc/apache/srm.conf. The division between these three files was relatively
Probably the best way to understand httpd.conf is to read through it. It's pretty long and contains a large number of comments. Most entries can be left the way there are, so we won't list the entire file here: instead we'll look at the parameters that may need change. We'll look at the system-wide features in the following list, and host-related features in the next section.
ServerType states whether you start it from inetd or standalone (the default). It's not a good idea to start httpd from inetd, so you should leave this entry ServerRoot claims to be the path to the configuration files, but in fact the files are stored in the ScoreBoardFile suggest that you should check to see if the system creates one. Don't bother: FreeBSD doesn't create this file, and you don't need to worry about it.HTTP/1.1 draft, allows persistent connections. These long-lived HTTP sessions allow multiple requests to be sent over the same TCP connection, and in some cases have been shown to result in an almost 50% MinSpareServers, MaxSpareServers, StartServers, Max-Clients and MaxRequestsPerChild are used for server tuning. The default values should work initially, but if you have a lot of Web traffic, you should consider changing them.modules. A lot of apache functionality is optional, and you include it by including a module. We'll look at this in more detail below.ProxyRequests allows Apache to function as a proxy server. We'll look at this in more detail below.Cache apply only to proxy servers, so we'll look at them below as well.Directorylndex is a list of names that httpd recognizes as the main page ("index") in the directory. Traditionally it's index.html. This is the means by which httpd changes a directory name into an index. It searches for the names in the order specified. For example, if you're using PHP, Directorylndex gets set to the string index.php index.php3 index.html, and that's the sequence in which it looks for a page.The file ends with a commented out VirtualHost section. We'll look at it in detail in the next section, along with a number of parameters that appear elsewhere in the configuration file, but that relate to virtual hosts.
Running and maintaining a web server is enough work that you might want to use the same server to host several sets of web pages, for example for a number of different organizations. apache calls this feature virtual hosts, and it offers a lot of support for them.
There's a good reason to keep the "main" server information: it serves as defaults for all virtual hosts, which can make the job of adding a virtual host a lot easier.
Consider your setup at http://example.org: you may run your own web pages and also a set of pages for http://biguser.com (see page 310). To do this, you add the following section to /usr/local/etc/apache/httpd.conf:
<VirtualHost *> ServerAdmin grog@example.org DocumentRoot /usr/local/www/biguser Where we put the web pages ServerName www.biguser.com the name that the server will claim to be ServerAlias biguser.com alternative server name ErrorLog /var/log/biguser/error_log TransferLog /var/log/biguser/access_log Options +FollowSymLinks Options +SymLinksIfOwnerMatch </VirtualHost>
If you look at the VirtualHost definition. They are the corresponding parameters for the "main" web server. They have the same meaning, so we'll look at them here.
ServerAdmin is the mail ID of the system administrator. For the main server, it's set to you@your.address, which obviously needs to be changed. You don't necessarily need a ServerAdmin for each virtual domain; that depends on how you run the system.<Directory /> Options FollowSymLinks AllowOverride None </Directory>
The / in the first line indicates the local directory to which these settings should apply. For once, this is really the DocumentRoot: they're system-wide defaults, and though you don't have to worry about apache playing around in your root file system, that's the only directory of which all other directories are Options directive ensures that the server can follow AllowOverride directive in the discussion of the .htaccess file below.
There's a separate entry for the
<Directory "/usr/local/www/data"> Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny Allow from all </Directory>
In this case, we have two additional options:
Indexes allows httpd to display the contents of a directory if no index file, with a name defined in DirectoryIndex, is present. Without this option, if there is no index file present, you will not be able to access the directory at all.MultiViews allows content-based Note that if you change the name of the default data directory, you should also change the name on the Directory invocation.
We'll look at the remaining entries in more detail when we see them again in the discussion of the .htaccess file.
ServerName. For example, www.example.org is a CNAME for freebie.example.org (see page 370), and if you don't set this value, clients will access www.example.org, but the server will return the name freebie.example.org.Options +SymLinksIfOwnerMatch limits following Options directive specifies all the options: it doesn't merge the + sign indicates that the option specified should be added to the defaults.After restarting with these parameters. If you don't define a virtual host, the server will access the main web pages (defined by the main DocumentRoot in entry /usr/local/etc/apache/access.conf).
httpd logs accesses and errors to the files you specify. It's worth understanding what's inside them. The following example shows five log entries. Normally each entry is all on a very long line.
p50859b17.dip.t-dialin.net - - name of system, more [01/Nov/2002:07:06:12 +1030] date of access "GET /Images/yaoipower.jpeg HTTP/1.1" HTML command 200 status (OK) 19365 length of data transfer aceproxy3.acenet.net.au - - [01/Nov/2002:07:35:34 +1030] "GET /Images/randomgal.big.jpeg HTTP/1.0" 304 - status (cached) 218.24.24.27 - - system without reverse DNS [01/Nov/2002:07:39:55 +1030] "GET /scripts/root.exe?/c+dir HTTP/1.0" looking for an invalid file 404 284 status (not found) 218.24.24.27 - - [01/Nov/2002:07:39:56 +1030] "GET /MSADC/root.exe?/c+dir HTTP/1.0" 404 282 218.24.24.27 - - [01/Nov/2002:07:39:56 +1030] "GET /c/winnt/system32/cmd.exe?/c+dir HTTP/1.0" 404 292 218.24.24.27 - - [01/Nov/2002:07:40:00 +1030] "GET /_vti_bin/..%255c../..%255c../..%255c../winnt/system32/cmd.exe?/c+dir HTTP/1.0" 404 323
The fields in the log file are separated by blanks, so empty entries are replaced by a - character. In this example, the second and third fields are always empty. They're used for identity checks and authorization.
To get the names of the clients, you need to specify the HostnameLookups on directive. This requires a DNS lookup for every access, which can be relatively slow.
Although we specified hostname lookups, the last four entries don't have any name: the system doesn't have reverse DNS. They come from a Microsoft machine
Sometimes you want to restrict access to a web server, either for specific directories or for the web site as a whole. apache has a number of options to limit access. One possibility is to set options in /usr/local/etc/apache/httpd.conf to cover an individual host, but this is seldom useful. It's more likely that you will want to restrict access to specific directories, and it's easier to do that in the file .htaccess in the same directory.
For apache to even look at .htaccess, you need to change the configuration file, however: by default, it disables the use of .htaccess a together, as we saw above:
<Directory /> Options FollowSymLinks AllowOverride None </Directory>
For it to work, you'll have to change the AllowOverride parameter to some other value. There are five categories of entries that you can allow in .htaccess files:
AuthConfig allows .htaccess to include authorization directives.FileInfo allows the use of directives controlling document types.Indexes allows the use of directives controlling directory indexing.Limit allows the use of directives controlling host access.Options allows the use of directives controlling specific directory features.You can find more details in /usr/local/share/doc/apache/manual/mod/core.html.
The most common use of the .htaccess is to require that users authorize themselves before accessing a directory. In this case, the browser will pop up a window like this:
(рис 25.1)
To achieve this, add something like this to your .htaccess file:
AuthType Basic AuthName grog AuthDBUserFile /usr/local/etc/apache/passwd Require valid-user
This method is similar to normal login authentication. You need a password file, which you can create and update with dbmmanage:
# dbmmanage /usr/local/etc/apache/passwd adduser grog New password: Re-type new password: User grog added with password encrypted to OzREW8Xx5hUAs using crypt # dbmmanage /usr/local/etc/apache/passwd adduser guest New password: Re-type new password: User guest added with password encrypted to hFCYwd23ftHE6 using crypt
This adds passwords for users grog and guest. The AuthName suggests a name to authenticate, but Require valid-user states that it can be any user. Even if you don't care which user logs in, you need to specify an AuthName line. If you do insist that only user grog can log in, you can write:
Require user grog
This will fail the authentication for any other user. You can also specify a list of users or groups. For example, you might add the following line:
AuthGroupFile /usr/local/etc/apache/group Require group bigshots
/usr/local/etc/apache/group might then contain:
bigshots: davidb davidp gordon grog liz malcolm
This will allow any of the users specified on this line to access the directory.
apache offers a large quantity of optional functionality, which it provides in the form of dynamically LoadModule and tells httpd which dynamic modules to load. The order is important; don't change it.
Apache is capable of operating as a
Unfortunately, by default the current version of Apache does not support proxy servers. You need to rebuild the package manually after enabling it in the configuration file. See the file INSTALL in the port build directory for more details. This file will be present after building Apache from source, and it will have a name like /usr/ports/www/apache13/work/apache1.3.23/src/INSTALL.Inaddition to ProxyRequests to On to enable the
One reason for enabling the
The Cache parameters are commented out by default. If you uncomment them, you should uncomment them all except possibly NoCache. When setting these values, change the name of the directory CacheRoot. A good name might be /usr/local/www/proxy.
When you install apache, it
# apachectl start start httpd # apachectl stop stop httpd # apachectl restart restart httpd, or start if not running # apachectl graceful restart httpd "gracefully," or start if not running # apachectl configtest do a configuration syntax test
The difference between a normal and a "graceful" restart is that the graceful restart waits for existing connections to complete before restarting the individual
A number of processes are needed to provide NFS server functionality:
monitoring service.
In addition:
A number of security
NFS was developed at a time when users were relatively trusted. precautions are not overly
file system options systems
systems is a list of systems allowed to mount the file system. The only required field is the name of the file system, but if you're on the Internet, you should at least limit the number of systems that can mount your file systems. By default any system on the Net can mount your file systems.
There are a number of options. Here are the more important ones:
-maproot option describes how to treat root. By default, root does not have special privileges on the nobody, which is user 65534 (or -2). You can change this with the -maproot option. For example, to map root to the real root user for a specific file system, you would add -maproot=0 to the line describing the file system.-mapall option maps the user IDs of other users. This is relatively uncommon. See the man page exports(5) for more details.-ro option restricts access to read-only.–network option restricts the access to systems on the specified network.-alldirs option allows remote clients to mount any directory in the file system directly. Without this option, remote clients can only mount the -alldirs can be of use during the discussion of diskless booting on page 543.If you come from a System V background, you'll notice that the mechanism is different. /etc/exports corresponds in concept roughly to System V's /etc/dfs/dfstab file, except that the share statement does not exist.
To grant access to a file system, it's not enough to change the contents of /etc/exports: you also need to tell mountd that you have done so. You do this by the relatively common method of sending a SIGHUP) to mountd:
# killall -HUP mountd
A typical /etc/exports for presto might be:
/ -maproot=0 presto bumble wait gw /usr -maproot=0 -alldirs -network 223.147.37.0
This allows root access to both file systems. Only the trusted systems presto, bumble, wait and gw are allowed to access the root file system, whereas any system on the local network may access /usr.
BSD UNIX and the Internet grew up together, but it took other vendors a long time to accept the Internet Protocols. In that time, a number of other protocols arose. We've already mentioned X.25 and SNA, currently both not supported by FreeBSD. The protocols that grew up in the DOS world are more widespread, in particular Novell's IPX and Microsoft's Common Internet File System, or CIFS. CIFS was previously known as SMB (Server Message Block).
IPX support is relatively rudimentary. FreeBSD includes an IPX routing daemon, IPXrouted. See the man page IPXrouted(8) for further information. IPX is going out of use, so it's unlikely that support for it will improve. By contrast, Microsoft's
you can get even more information, including support and a
Samba includes a number of programs, most of which we don't touch on here. The ones we look at are:
Install Samba from the port:
# cd /usr/ports/net/samba # make install
This operation installs the Samba binaries in /usr/local/bin, the standard location for additional binaries on a BSD system, and the daemons smbd and nmbd in /usr/local/sbin. These locations are appropriate for FreeBSD, but they are not the locations that the Samba documentation recommends. It also installs the man pages in /usr/local/man, where the man program can find them. Finally, it installs a sample configuration file in /usr/local/etc/smb.conf.default. We'll look at how to configure Samba below.
There are a number of security
root. smbd should be executable by all. Don't make it setuid. If an individual user runs it, it runs with their permissions.root, since they may contain sensitive information.root can change it.
The Samba documentation recommends setting the directory readable and writeable only by root. Depending on what other configuration files you have in /etc/local/etc, this could cause problems.
The main component of Samba is smbd, the SMB daemon. In addition, you need the Samba name daemon, nmbd, which supplies NetBIOS name services for Samba. smbd requires a configuration file, which we'll look at below, while you don't normally need one for nmbd. By default, nmbd maps DNS host names (without the domain part) to NetBIOS names, though it can perform other functions if you need them. In this chapter we'll assume the nmbd(8) for other possibilities.
You have two choices of how to run smbd and nmbd: you can start them at
When you install Samba from the Ports Collection, it installs a file /usr/local/etc/rc.d/samba.sh.sample .You just need to rename it to /usr/local/etc/rc.d/samba.sh. As the name suggests, it's a shell script. You can modify it if necessary, but it's usually not necessary.
The man page for smbd gives a number of parameters to specify the configuration file and the log file. As long as you stick to the specified file names, you shouldn't need to change anything: by default, smbd looks for the configuration file at /usr/local/etc/smb.conf, and this file contains the names of the other files.
To run the daemons from inetd,
# in front. Remove the # to show the lines as they are here. If your /etc/inetd.conf doesn't contain these lines, add them.
netbios-ssn stream tcp nowait root /usr/local/sbin/smbd smbd netbios-ns dgram udp wait root /usr/local/sbin/nmbd nmbd swat stream tcp nowait/400 root /usr/local/sbin/swat swat
swat is an administration tool that we don't discuss here.
# killall -1 inetd send a SIGHUP
The Samba configuration file describes the services that the daemon offers. The port installs a sample configuration file in /usr/local/etc/smb.conf.default. You can use it as the basis of your own configuration file, which must be called /usr/local/etc/smb.conf: simply copy the file, and then edit it as described below.
The configuration file is divided into sections identified by a label in [global], [homes] and [printers], all of which are optional. We look at them in the following sections.
As the name suggests, the [global] section defines parameters that either apply to the server as a whole, or that are defaults for the other services. The interesting ones for us are:
workgroup parameter defines the Microsoft workgroup to which this server belongs. Set it to match the Microsoft environment. In these examples, we'll assume:
workgroup = EXAMPLE
printing entry specifies what kind of printer support Samba provides. Current versions of Samba support CUPS. If you are using CUPS (not described in this book), you don't need to do anything. Otherwise set:
printcap name = /etc/printcap printing = bsd
guest account is the account (in UNIX terms: user ID) to use if no password is supplied. You probably want to define a guest account, since many Microsoft clients don't use user IDs. Ensure that the privileges are set appropriately. Alternatively, alter the parameter to point to an existing user.encrypt passwords to yes.dns proxy to yes.log file = /var/log/samba.log.%m
socket options is hardly mentioned in the documentation, but it's very important: many Microsoft implementations of TCP/IP are TCP_NODELAY and IPTOS_LOWDELAY, which can speed up the The [homes] section allows clients to connect to their home directories without needing an entry in the configuration file. If this section is present, and an incoming request specifies a service that is not defined in the configuration file, Samba checks if it matches a user ID. If it does, and if the specified password is correct, Samba creates a service that supplies the user's home directory.
The following options are of interest in the [homes] section:
writeable can be yes or no, and specifies whether the user is allowed to write to the directory.create mode specifies the permission bits (in public specifies whether other users are allowed access to this directory. In combination with a guest user, this can be a serious security liability.The [printers] section describes printing services. It doesn't need the names of the printers: if it doesn't find the specified service, either in the configuration file or in the [homes] section, if it exists, it looks for them in the /etc/printcap file.
The Samba documentation claims that Samba can recognize BSD printing system automatically, but this is not always correct. Ensure that you have the following entries:
printing = bsd in the [global] sectionW print command = lpr -r -P'%p' '%s' in the [printers] sectionW
Note the printable option in the [printers] section: this is the option that distinguishes between printers ("yes")and no").
Samba takes any section name except for [global], [homes] or [printers] as the definition of a service. A typical example might be:
[ftp] comment = ftp server file area path = /var/spool/ftp/pub read only = yes public = yes write list = grog
This entry defines access to the anonymous ftp section. Anybody can read it, but only user grog can write to it.
Samba uses a separate password file, /usr/local/private/secrets.tdb. To set up users, use the smbpasswd command, which copies the information from the system password file:
# smbpasswd -a grog New SMB password: Retype new SMB password: as usual, no echo Password changed for user grog.
Once you have performed the steps described above, you can proceed to test the installation. First, run testparm to check the correctness of the configuration file:
$ testparm Load smb config files from /usr/local/etc/smb.conf Processing section "[homes]" Processing section "[printers]" Processing section "[ftp]" Processing section "[src]" Processing section "[grog]" Loaded services file OK. Press enter to see a dump of your service definitions Press Enter Global parameters: lots of information which could be of use in debugging [homes] comment = Home Directories read only = No [printers] comment = All Printers path = /var/spool/samba guest ok = Yes printable = Yes browseable = No [ftp] comment = ftp server file area path = /var/spool/ftp/pub write list = grog guest ok = Yes [grog] path = /home/grog valid users = grog read only = No
As you see, testparm spells out all the parameters that have been created, whether explicitly or by default. If you run into problems, this is the first place to which to return.
Next, check that you can log in with smbclient. If you're running the servers as daemons, start them now. If you're starting them from inetd, you don't need to do anything.
$ smbclient -L freebie -U grog added interface ip=223.147.37.1 bcast=223.147.37.255 nmask=255.255.255.0 Password: as usual, no echo Domain=[EXAMPLE] OS=[Unix] Server=[Samba 2.2.7a] Sharename Type Comment --------- ---- ------- homes Disk Home Directories ftp Disk ftp server file area grog Disk IPC$ IPC IPC Service (Samba Server) ADMIN$ Disk IPC Service (Samba Server) Server Comment ------ ------- FREEBIE Samba Server PRESTO Samba Server Workgroup Master --------- ------ EXAMPLE PRESTO
If you get this far, your password authentication is working. Finally, try to access the shares. Samba services are specified in Microsoft format: \\system\service. To make this worse, UNIX interprets the \ character specially, so you would need to repeat the character. For example, to access the ftp service on freebie, you would have to enter \\\\freebie\\ftp. Fortunately, smbclient understands UNIX-like names, so you can write //freebie/ftp instead.
To test, start smbclient from another system:
$ smbclient //freebie/ftp -U grog added interface ip=223.147.37.1 bcast=223.147.37.255 nmask=255.255.255.0 Password: as usual, no echo Domain=[EXAMPLE] OS=[Unix] Server=[Samba 2.2.7a] smb: \> ls . DR 0 Wed Jan 29 12:06:29 2003 .. D 0 Sat Oct 26 10:36:29 2002 instant-workstation-1.0.tar.gz 9952 Mon Mar 19 11:49:01 2001 xtset-1.0.tar.gz 4239 Mon Aug 5 16:44:14 2002 gpart-0.1h.tbz.tgz 27112 Tue Aug 27 10:07:59 2002
If you get this far, Samba is working. The next step is to attach to the services from the Microsoft machines. That's not a topic for this book. Note, however, that Samba only works with TCP/IP transport, not with NetBEUI.
You can display the status of Samba connections with smbstatus. For example,
$ smbstatus Samba version 2.2.7a Service uid gid pid machine -------------------------------------- ftp grog example 37390 freebie (223.147.37.1) Mon Mar 31 13:48:13 2003 No locked files
Для получения официальных документов о завершении программы дополнительного профессионального образования (удостоверения о повышении квалификации, дипломов о профессиональной переподготовке и MBA) необходимо предоставить:
Внимание! Вы можете не заказывать доставку бумажной версии официального документы, а скачать его в электронном виде и распечатать самостоятельно. Информация о выданном документе в течение 1 месяца загружается в Федеральную информационную систему «Федеральный реестр сведений о документах об образовании и (или) о квалификации, документах об обучении» - ФИС ФРДО.
Доступ на новый сайт осуществляется с использованием адреса электронной почты, который был указан вами при регистрации на "старом". Мы постарались перенести все ваши данные с прежнего ресурса, однако не исключена вероятность потери части информации.
При возникновении проблемы со входом, воспользуйтесь функцией сброса пароля
Если вы обнаружите несоответствия, пожалуйста, сообщите нам.