Author: Sture

Samba SMB/CIFS Server

Samba SMB/CIFS Server

Description

Samba is an attempt to implement an Active Directory compatible Domain Controller.

In short, you can join a WinNT, Win2000, WinXP or Win2003 member server to a Samba4 domain, and it will behave much as it does in AD, including Kerberos domain logins where applicable.

N.B.: This document descries how to install and configure a standalone Samba 4.4 server with netbios disable for reduced network traffic.

WWW: http://www.samba.org/.

Preparation for Installation

Start PuTTY on a Windows PC, Terminal on a Mac or similar terminal application on a Linux PC.

In this example Terminal on a Mac is used.

Open a remote SSH session to the server with:

Mac:~ user$ ssh user@192.168.1.4 [enter]
N.B.: Replace user@192.168.1.4 with User ID and IP Address on Your server!
[user@server ~]$

Enable superuser privileges with:

[user@server ~]$ sudo -s [enter]
Password: <-- passwd [enter]
[root@server /usr/home/user]#

N.B.: Enter user password, not the root password!

Installation

Search for samba in the remote package repositories with:

[root@server /usr/home/user]# pkg search samba [enter]
p5-Samba-LDAP-0.05_2           Manage a Samba PDC with an LDAP Backend
p5-Samba-SIDhelper-0.0.0_3     Create SIDs based on G/UIDs
samba-nsupdate-9.8.6_1         nsupdate utility with GSS-TSIG support
samba-virusfilter-0.1.3_1      On-access anti-virus filter for Samba
samba36-3.6.25_3               Free SMB and CIFS client and server for Unix
samba36-libsmbclient-3.6.25_2  Shared lib from the samba package
samba36-nmblookup-3.6.25       NetBIOS Name lookup tool
samba36-smbclient-3.6.25       Samba "ftp-like" client
samba42-4.2.14                 Free SMB/CIFS and AD/DC server and client for Unix
samba43-4.3.13_1               Free SMB/CIFS and AD/DC server and client for Unix
samba44-4.4.8_1                Free SMB/CIFS and AD/DC server and client for Unix
[root@server /usr/home/user]#

In this example samba46 will be installed as a standalone server.

Install port samba46 with;

[root@server /usr/home/user]# pkg install net/samba46 [enter]
Updating FreeBSD repository catalogue...
FreeBSD repository is up to date.
All repositories are up to date.
The following 35 package(s) will be affected (of 0 checked):

New packages to be INSTALLED:
        samba46: 4.6.4_1
        libsunacl: 1.0
        gnutls: 3.5.13
        trousers: 0.3.14_1
        tpm-emulator: 0.7.4_2
        gmp: 6.1.2
        p11-kit: 0.23.7
        libtasn1: 4.12
        ca_root_nss: 3.31
        libffi: 3.2.1
        nettle: 3.3
        libidn2: 2.0.2
        libunistring: 0.9.7
        openldap-client: 2.4.45
        python27: 2.7.13_6
        readline: 7.0.3
        python2: 2_3
        py27-dnspython: 1.15.0
        py27-setuptools: 36.0.1
        tevent: 0.9.31
        talloc: 2.1.9
        py27-iso8601: 0.1.11
        popt: 1.16_2
        libinotify: 20160505
        gamin: 0.1.10_9
        glib: 2.50.2_2,1
        perl5: 5.24.1_1
        pcre: 8.40_1
        libiconv: 1.14_10
        tdb: 1.3.12,1
        ldb: 1.1.29_1
        libarchive: 3.3.1,1
        expat: 2.2.0_1
        lzo2: 2.10_1
        liblz4: 1.7.5,1

Number of packages to be installed: 35

The process will require 327 MiB more space.
61 MiB to be downloaded.

Proceed with this action? [y/N]: y [enter]
[1/35] Fetching samba46-4.6.4_1.txz: 100%   23 MiB   6.0MB/s    00:04
[2/35] Fetching libsunacl-1.0.txz: 100%    7 KiB   6.9kB/s    00:01
[3/35] Fetching gnutls-3.5.13.txz: 100%    2 MiB   2.2MB/s    00:01
[4/35] Fetching trousers-0.3.14_1.txz: 100%  463 KiB 474.0kB/s    00:01
[5/35] Fetching tpm-emulator-0.7.4_2.txz: 100%  112 KiB 114.5kB/s    00:01
[6/35] Fetching gmp-6.1.2.txz: 100%  463 KiB 474.1kB/s    00:01
[7/35] Fetching p11-kit-0.23.7.txz: 100%  391 KiB 400.6kB/s    00:01
[8/35] Fetching libtasn1-4.12.txz: 100%  603 KiB 617.3kB/s    00:01
[9/35] Fetching ca_root_nss-3.31.txz: 100%  331 KiB 338.8kB/s    00:01
[10/35] Fetching libffi-3.2.1.txz: 100%   34 KiB  35.2kB/s    00:01
[11/35] Fetching nettle-3.3.txz: 100%    1 MiB   1.1MB/s    00:01
[12/35] Fetching libidn2-2.0.2.txz: 100%   96 KiB  98.3kB/s    00:01
[13/35] Fetching libunistring-0.9.7.txz: 100%  602 KiB 616.8kB/s    00:01
[14/35] Fetching openldap-client-2.4.45.txz:   7%   72 KiB  73.7kB/s    00:13 ET[14/35] Fetching openldap-client-2.4.45.txz: 100%    1 MiB   1.0MB/s    00:01   
[15/35] Fetching python27-2.7.13_6.txz: 100%   10 MiB   3.6MB/s    00:03
[16/35] Fetching readline-7.0.3.txz: 100%  334 KiB 342.2kB/s    00:01
[17/35] Fetching python2-2_3.txz: 100%    1 KiB   1.1kB/s    00:01
[18/35] Fetching py27-dnspython-1.15.0.txz: 100%  170 KiB 174.1kB/s    00:01
[19/35] Fetching py27-setuptools-36.0.1.txz:  47%  208 KiB 213.0kB/s    00:01 ET[19/35] Fetching py27-setuptools-36.0.1.txz: 100%  439 KiB 450.0kB/s    00:01   
[20/35] Fetching tevent-0.9.31.txz: 100%   48 KiB  48.7kB/s    00:01
[21/35] Fetching talloc-2.1.9.txz: 100%   52 KiB  53.4kB/s    00:01
[22/35] Fetching py27-iso8601-0.1.11.txz: 100%   12 KiB  11.9kB/s    00:01
[23/35] Fetching popt-1.16_2.txz: 100%   60 KiB  61.9kB/s    00:01
[24/35] Fetching libinotify-20160505.txz: 100%   18 KiB  18.7kB/s    00:01
[25/35] Fetching gamin-0.1.10_9.txz: 100%   49 KiB  50.5kB/s    00:01
[26/35] Fetching glib-2.50.2_2,1.txz: 100%    3 MiB   2.9MB/s    00:01
[27/35] Fetching perl5-5.24.1_1.txz: 100%   13 MiB   3.5MB/s    00:04
[28/35] Fetching pcre-8.40_1.txz: 100%    1 MiB   1.1MB/s    00:01
[29/35] Fetching libiconv-1.14_10.txz: 100%  599 KiB 613.6kB/s    00:01
[30/35] Fetching tdb-1.3.12,1.txz: 100%   83 KiB  85.4kB/s    00:01
[31/35] Fetching ldb-1.1.29_1.txz: 100%  199 KiB 203.7kB/s    00:01
[32/35] Fetching libarchive-3.3.1,1.txz: 100%  694 KiB 710.3kB/s    00:01
[33/35] Fetching expat-2.2.0_1.txz: 100%  102 KiB 104.4kB/s    00:01
[34/35] Fetching lzo2-2.10_1.txz: 100%  113 KiB 115.3kB/s    00:01
[35/35] Fetching liblz4-1.7.5,1.txz: 100%   95 KiB  97.5kB/s    00:01
Checking integrity... done (0 conflicting)
[1/35] Installing libffi-3.2.1...
[1/35] Extracting libffi-3.2.1: 100%
[2/35] Installing readline-7.0.3...
[2/35] Extracting readline-7.0.3: 100%
[3/35] Installing python27-2.7.13_6...
[3/35] Extracting python27-2.7.13_6: 100%
[4/35] Installing gmp-6.1.2...
[4/35] Extracting gmp-6.1.2: 100%
[5/35] Installing python2-2_3...
[5/35] Extracting python2-2_3: 100%
[6/35] Installing tpm-emulator-0.7.4_2...
===> Creating groups.
Creating group '_tss' with gid '601'.
===> Creating users
Creating user '_tss' with uid '601'.
[6/35] Extracting tpm-emulator-0.7.4_2: 100%
[7/35] Installing libtasn1-4.12...
[7/35] Extracting libtasn1-4.12: 100%
[8/35] Installing ca_root_nss-3.31...
[8/35] Extracting ca_root_nss-3.31: 100%
[9/35] Installing libunistring-0.9.7...
[9/35] Extracting libunistring-0.9.7: 100%
[10/35] Installing talloc-2.1.9...
[10/35] Extracting talloc-2.1.9: 100%
[11/35] Installing perl5-5.24.1_1...
[11/35] Extracting perl5-5.24.1_1: 100%
[12/35] Installing pcre-8.40_1...
[12/35] Extracting pcre-8.40_1: 100%
[13/35] Installing libiconv-1.14_10...
[13/35] Extracting libiconv-1.14_10: 100%
[14/35] Installing trousers-0.3.14_1...
===> Creating groups.
Using existing group '_tss'.
===> Creating users
Using existing user '_tss'.
[14/35] Extracting trousers-0.3.14_1: 100%
[15/35] Installing p11-kit-0.23.7...
[15/35] Extracting p11-kit-0.23.7: 100%
[16/35] Installing nettle-3.3...
[16/35] Extracting nettle-3.3: 100%
[17/35] Installing libidn2-2.0.2...
[17/35] Extracting libidn2-2.0.2: 100%
[18/35] Installing openldap-client-2.4.45...
[18/35] Extracting openldap-client-2.4.45: 100%
[19/35] Installing py27-setuptools-36.0.1...
[19/35] Extracting py27-setuptools-36.0.1: 100%
[20/35] Installing tevent-0.9.31...
[20/35] Extracting tevent-0.9.31: 100%
[21/35] Installing popt-1.16_2...
[21/35] Extracting popt-1.16_2: 100%
[22/35] Installing glib-2.50.2_2,1...
[22/35] Extracting glib-2.50.2_2,1: 100%
No schema files found: doing nothing.
[23/35] Installing tdb-1.3.12,1...
[23/35] Extracting tdb-1.3.12,1: 100%
[24/35] Installing expat-2.2.0_1...
[24/35] Extracting expat-2.2.0_1: 100%
[25/35] Installing lzo2-2.10_1...
[25/35] Extracting lzo2-2.10_1: 100%
[26/35] Installing liblz4-1.7.5,1...
[26/35] Extracting liblz4-1.7.5,1: 100%
[27/35] Installing libsunacl-1.0...
[27/35] Extracting libsunacl-1.0: 100%
[28/35] Installing gnutls-3.5.13...
[28/35] Extracting gnutls-3.5.13: 100%
[29/35] Installing py27-dnspython-1.15.0...
[29/35] Extracting py27-dnspython-1.15.0: 100%
[30/35] Installing py27-iso8601-0.1.11...
[30/35] Extracting py27-iso8601-0.1.11: 100%
[31/35] Installing libinotify-20160505...
[31/35] Extracting libinotify-20160505: 100%
[32/35] Installing gamin-0.1.10_9...
[32/35] Extracting gamin-0.1.10_9: 100%
[33/35] Installing ldb-1.1.29_1...
[33/35] Extracting ldb-1.1.29_1: 100%
[34/35] Installing libarchive-3.3.1,1...
[34/35] Extracting libarchive-3.3.1,1: 100%
[35/35] Installing samba46-4.6.4_1...
Extracting samba46-4.6.4_1: 100%
Message from python27-2.7.13_6:
===========================================================================

Note that some standard Python modules are provided as separate ports
as they require additional dependencies. They are available as:

bsddb           databases/py-bsddb
gdbm            databases/py-gdbm
sqlite3         databases/py-sqlite3
tkinter         x11-toolkits/py-tkinter

===========================================================================
Message from ca_root_nss-3.31:
********************************* WARNING *********************************

FreeBSD does not, and can not warrant that the certification authorities
whose certificates are included in this package have in any way been
audited for trustworthiness or RFC 3647 compliance.

Assessment and verification of trust is the complete responsibility of the
system administrator.

*********************************** NOTE **********************************

This package installs symlinks to support root certificates discovery by
default for software that uses OpenSSL.

This enables SSL Certificate Verification by client software without manual
intervention.

If you prefer to do this manually, replace the following symlinks with
either an empty file or your site-local certificate bundle.

  * /etc/ssl/cert.pem
  * /usr/local/etc/ssl/cert.pem
  * /usr/local/openssl/cert.pem

***************************************************************************
Message from perl5-5.24.1_1:
The /usr/bin/perl symlink has been removed starting with Perl 5.20.
For shebangs, you should either use:

#!/usr/local/bin/perl

or

#!/usr/bin/env perl

The first one will only work if you have a /usr/local/bin/perl,
the second will work as long as perl is in PATH.
Message from trousers-0.3.14_1:
To run tcsd automatically, add the following line to /etc/rc.conf:

tcsd_enable="YES"

You might want to edit /usr/local/etc/tcsd.conf to reflect your setup.

If you want to use tcsd with software TPM emulator, use the following
configuration in /etc/rc.conf:

tcsd_enable="YES"
tcsd_mode="emulator"
tpmd_enable="YES"

To use TPM, add your_account to '_tss' group like following:

# pw groupmod _tss -m your_account
Message from openldap-client-2.4.45:
************************************************************

The OpenLDAP client package has been successfully installed.

Edit
  /usr/local/etc/openldap/ldap.conf
to change the system-wide client defaults.

Try `man ldap.conf' and visit the OpenLDAP FAQ-O-Matic at
  http://www.OpenLDAP.org/faq/index.cgi?file=3
for more information.

************************************************************
Message from libinotify-20160505:
============================================================================

Libinotify functionality on FreeBSD is missing support for

  - detecting a file being moved into or out of a directory within the
    same filesystem
  - certain modifications to a symbolic link (rather than the
    file it points to.)

in addition to the known limitations on all platforms using kqueue(2)
where various open and close notifications are unimplemented.

This means the following regression tests will fail:

Directory notifications:
   IN_MOVED_FROM
   IN_MOVED_TO

Open/close notifications:
   IN_OPEN
   IN_CLOSE_NOWRITE
   IN_CLOSE_WRITE

Symbolic Link notifications:
   IN_DONT_FOLLOW
   IN_ATTRIB
   IN_MOVE_SELF
   IN_DELETE_SELF

Kernel patches to address the missing directory and symbolic link
notifications are available from:

https://github.com/libinotify-kqueue/libinotify-kqueue/tree/master/patches

=============================================================================
You might want to consider increasing the kern.maxfiles tunable if you plan
to use this library for applications that need to monitor activity of a lot
of files.

If the default on your system is too low, add the following line to
/boot/loader.conf, then reboot the system:

    kern.maxfiles="25000"
=============================================================================
Message from gamin-0.1.10_9:
===============================================================================

Gamin will only provide realtime notification of changes for at most n files,
where n is the minimum value between (kern.maxfiles * 0.7) and
(kern.maxfilesperproc - 200). Beyond that limit, files will be polled.

If you often open several large folders with Nautilus, you might want to
increase the kern.maxfiles tunable (you do not need to set
kern.maxfilesperproc, since it is computed at boot time from kern.maxfiles).

For a typical desktop, add the following line to /boot/loader.conf, then
reboot the system:

    kern.maxfiles="25000"

The behavior of gamin can be controlled via the various gaminrc files.
See http://www.gnome.org/~veillard/gamin/config.html on how to create
these files.  In particular, if you find gam_server is taking up too much
CPU time polling for changes, something like the following may help
in one of the gaminrc files:

# reduce polling frequency to once per 10 seconds
# for UFS file systems in order to lower CPU load
fsset ufs poll 10

===============================================================================

===>   NOTICE:

The gamin port currently does not have a maintainer. As a result, it is
more likely to have unresolved issues, not be up-to-date, or even be removed in
the future. To volunteer to maintain this port, please create an issue at:

https://bugs.freebsd.org/bugzilla

More information about port maintainership is available at:

https://www.freebsd.org/doc/en/articles/contributing/ports-contributing.html#maintain-port
Message from samba46-4.6.4_1:
===============================================================================

How to start: http://wiki.samba.org/index.php/Samba4/HOWTO

* Your configuration is: /usr/local/etc/smb4.conf

* All the relevant databases are under: /var/db/samba4

* All the logs are under: /var/log/samba4

* Provisioning script is: /usr/local/bin/samba-tool

For additional documentation check: http://wiki.samba.org/index.php/Samba4

Bug reports should go to the: https://bugzilla.samba.org/

===============================================================================

Configuration

packet filter (pf)

Access to the Samba service must be enabled in the packet filter (pf) configuration file.

Start editing file /etc/pf.conf with:

[root@server /usr/home/user]# ee /etc/pf.conf [enter]

…and add port information to enable access to the Samba service from clients on the local network as in this example:

.
# Ports:
# 123 TCP       Network Time Protocol
# 445 TCP       Microsoft-DS SMB file sharing

tcp_pass="{ 123, 445 }"
.

Check /etc/pf.conf for errors, but do not load ruleset with:

[root@server /usr/home/user]# pfctl -vvnf /etc/pf.conf [enter]

…and then reload /etc/pf.conf with:

[root@server /usr/home/user]# service pf reload [enter]
Reloading pf rules.
[root@server /usr/home/user]#

Kernel Options

Edit kernel state defaults to handling of many files with:

[root@server /usr/home/user]# ee /etc/sysctl.conf [enter]

…and add text:

# $FreeBSD: releng/11.0/etc/sysctl.conf 112200 2003-03-13 18:43:50Z mux $
#
#  This file is read when going to multi-user and its contents piped thru
#  ``sysctl'' to adjust kernel values.  ``man 5 sysctl.conf'' for details.
#

# Uncomment this to prevent users from seeing information about processes that
# are being run under another UID.
#security.bsd.see_other_uids=0
kern.maxfiles=25600
kern.maxfilesperproc=16384
net.inet.tcp.sendspace=65536
net.inet.tcp.recvspace=65536

N.B.: I/O module, aio is part of the FreeBSD-RELEASE-11.1 kernel and due to this theres is no need to load it via /etc/rc.conf.

Storage Config

List current ZFS pool information with:

[root@server /usr/home/user]# zpool list [enter]
NAME    SIZE  ALLOC   FREE   FRAG  EXPANDSZ    CAP  DEDUP  HEALTH  ALTROOT
zroot  1.36T  2.30G  1.36T     0%         -     0%  1.00x  ONLINE  -
[root@server /usr/home/user]#

In this example zroot pool was found.

Samba 4 expects a filesystem which respects POSIX acls, but ZFS uses the nfsv4acl model.

We can configure ZFS to operate in passthrough mode and then tell Samba to use nfsv4 acls.

In addition, we want to make the volume’s .zfs/snapshot directory visible. This will allow us to present snapshots as Volume Shadow Copies, which appear to Windows clients as Previous Versions of the volume.

Creates a dataset where the SMB file shares will be stored with:

[root@server /usr/home/user]# zfs create -o compression=lz4 -o mountpoint=/smb zroot/smb [enter]
[root@server /usr/home/user]#

Set the ACL Mode and Inheritance to passthrough with:

[root@server /usr/home/user]# zfs set aclmode=passthrough zroot/smb [enter]
[root@server /usr/home/user]# zfs set aclinherit=passthrough zroot/smb [enter]
[root@server /usr/home/user]#

Get ACL information with:

[root@server /usr/home/user]# getfacl /smb [enter]
# file: /smb
# owner: root
# group: wheel
            owner@:rwxp--aARWcCos:------:allow
            group@:r-x---a-R-c--s:------:allow
         everyone@:r-x---a-R-c--s:------:allow
[root@server /usr/home/user]#

Service start on boot

List installed Samba services with:

[root@server /usr/home/user]# service -r | grep /samba [enter]
/usr/local/etc/rc.d/samba_server
[root@server /usr/home/user]#

Find the rcvar for /usr/local/etc/rc.d/samba_server with:

[root@server /usr/home/user]# /usr/local/etc/rc.d/samba_server rcvar [enter]
# samba_server
#
samba_server_enable="NO"
#   (default: "")

# nmbd
#
nmbd_enable="NO"
#   (default: "")

# smbd
#
smbd_enable="NO"
#   (default: "")

# winbindd
#
winbindd_enable="NO"
#   (default: "")

[root@server /usr/home/user]#

NetBIOS generally refers to the NetBIOS over TCP/IP protocol, which is considered a legacy protocol. It offers name resolution, file and printer sharing with devices that do not have DNS capabilities. It used to be essential in a Windows network, but is no longer necessary unless prior to Windows 2000 versions of Windows Clients are involved.

To start Samba without NetBIOS on system boot, add information to /etc/rc.conf, with this commands:

[root@server /usr/home/user]# echo '' >> /etc/rc.conf; echo '# Samba SMB Server' >> /etc/rc.conf; echo 'samba_server_enable="YES"' >> /etc/rc.conf; echo 'nmbd_enable="NO"' >> /etc/rc.conf [enter]
[root@server /usr/home/user]#

Samba Config File

Display where the configuration file should be put with:

[root@server /usr/home/user]# grep smb4.conf /usr/local/etc/rc.d/samba_server [enter]
#samba_server_config="/usr/local/etc/smb4.conf"
samba_server_config_default="/usr/local/etc/smb4.conf"
[root@server /usr/home/user]

Edit file /usr/local/etc/smb4.conf with:

[root@server /usr/home/user]# ee /usr/local/etc/smb4.conf [enter]

This is an Samba configuration example:

[global]
        interfaces = em0
        server string = FreeBSD Server - Samba %v
        workgroup = EXAMPLE
        log file = /var/log/samba4/%m.log
        max log size = 50
        load printers = No
        disable netbios = Yes
        map to guest = Bad User
        security = USER
        server role = standalone server
        deadtime = 15
        dns proxy = No
        idmap config * : backend = tdb
        delete veto files = Yes
        store dos attributes = Yes
        veto files = /Thumbs.db/.DS_Store/._.DS_Store/.apdisk/._*/
        strict locking = No
        directory name cache size = 0
        dos filemode = Yes
        acl allow execute always = Yes
        create mask = 0775
        directory mask = 0775
        invalid users = nobody root
        aio read size = 65536
        aio write behind = Yes
        aio write size = 65536
        max connections = 10
        write cache size = 65536


[files]
        comment = Files Samba Network Share
        path = /smb/files
        force group = staff
        inherit acls = Yes
        read only = No
        vfs objects = zfsacl
        nfs4: acedup = merge
        nfs4: mode = special


[homes]
        comment = User Home Network Volume
        path = /usr/home/%U/docs
        force group = staff
        read only = No
        valid users = %U


[public]
        comment = Public Network Share
        path = /smb/pub
        create mask = 0777
        directory mask = 0777
        force group = nogroup
        force user = nobody
        guest ok = Yes
        inherit acls = Yes
        read only = No
        vfs objects = zfsacl
        nfs4: mode = special
        nfs4: acedup = merge

N.B.: The veto file statement will delete all files in the list including all hidden ._* files uploaded by a Macintosh user.

Now let’s test the file for typos and other errors:

[root@server /usr/home/user]# /usr/local/bin/testparm | more [enter]

If you don’t see any error messages, then it’s good to go.

Samba File Shares Setup

Private SMB Share Setup

Create directory /smb/files with:

[root@server /usr/home/user]# mkdir /smb/files [enter]
[root@server /usr/home/user]#

Change owner and group for /smb/files with:

[root@server /usr/home/user]# chown -vv user:staff /smb/files [enter]
/smb/install: 0:0 -> 1001:20
[root@server /usr/home/user]#

Change /smb/pub mod with:

[root@server /usr/home/user]# chmod -vv 0755 /smb/files [enter]
/smb/files: 040755 [drwxr-xr-x ] -> 040755 [drwxr-xr-x ]
[root@server /usr/home/user]#

Local FreeBSD Users SMB Share Setup

List FreeBSD Users with:

[root@server /usr/home/user]# cat /etc/passwd | grep :10 [enter]
user:*:1001:1001:Ed User:/home/user:/usr/local/bin/bash
[root@server /usr/home/user]#

In this example one user user was found.

To hide critical files from the user when accessing the server via an SMB client on a Windows PC, Macintosh or Linux computer a docs will be created in the FreeBSD users home directory.

Create directory /home/user/docs with:

[root@server /usr/home/user]# mkdir /home/user/docs [enter]
[root@server /usr/home/user]#

Change owner and group for /smb/files with:

[root@server /usr/home/user]# chown -vv user:user /home/user/docs [enter]
/smb/install: 0:0 -> 1001:20
[root@server /usr/home/user]#

Change /home/user/docs mod with:

[root@server /usr/home/user]# chmod -vv 0755 /home/user/docs [enter]
/home/user/docs: 040755 [drwxr-xr-x ] -> 040755 [drwxr-xr-x ]
[root@server /usr/home/user]#

Public SMB Share Setup

Create directory /smb/pub with:

[root@server /usr/home/user]# mkdir /smb/pub [enter]
[root@server /usr/home/user]#

Change owner and group for /smb/pub with:

[root@server /usr/home/user]# chown -vv user:nobody /smb/pub [enter]
/smb/pub: 0:0 -> 1001:65534
[root@server /usr/home/user]#

Change /smb/pub mod with:

[root@server /usr/home/user]# chmod -vv 0777 /smb/pub [enter]
/smb/pub: 040755 [drwxr-xr-x ] -> 040777 [drwxrwxrwx ]
[root@server /usr/home/user]#

Start Samba

Manually start Samba daemons with:

[root@server /usr/home/user]# service samba_server start [enter]
Performing sanity check on Samba configuration: OK
Starting smbd.
[root@server /usr/home/user]#

Display content of the smbd log file with:

[root@server /usr/home/user]# cat /var/log/samba4/smbd.log [enter]
[2016/11/09 19:11:15.043835,  0] ../lib/util/become_daemon.c:124(daemon_ready)
  STATUS=daemon 'smbd' finished starting up and ready to serve connections
[root@server /usr/home/user]#

Samba User

Add a User

N.B.: Users must have an FreeBSD user account created before the user can be added as an Samba user!

Add a new FreeBSD user with primary group setting nogroup, additional group memberships staff and login setting nologin with:

[root@server /usr/home/user]# pw adduser user -c "John Smith" -d /nonexistent -g nogroup -G staff -s /usr/sbin/nologin [enter]
[root@server /usr/home/user]#

Verify the entry of user ‘John Smith’ with:

[root@server /usr/home/user]# cat /etc/passwd | egrep 'John Smith' [enter]
user:*:1003:1003:John Smith:/nonexistent:/usr/sbin/nologin
[root@server /usr/home/user]#

…and verify:

[root@server /usr/home/user]# id -p user [enter]
uid	user
groups	nogroup staff
[root@server /usr/home/user]#

Add the user to a group staff with:

[root@server /usr/home/user]# pw groupmod staff -m user [enter]
[root@server /usr/home/user]#

Add User to Samba User Database

Add the FreeBSD user to the Samba SAM database (Database of Samba Users) with:

[root@server /usr/home/user]# smbpasswd -a user [enter]
New SMB password:
Retype new SMB password:
Added user user.
[root@server /usr/home/user]#

Verfy entry of user ‘John Smith’ in the Samba SAM database (Database of Samba Users) with:

[root@server /usr/home/user]# pdbedit -L | grep user [enter]
user:1003:John Smith
[root@server /usr/home/user]#

Delete a User

Delete an account from the Samba SAM database (Database of Samba Users) with:

[root@server /usr/home/user]# pdbedit -x -u user [enter]
[root@server /usr/home/user]#

Delete the FreeBSD user account and home directory for user ‘user’ with:

[root@server /usr/home/user]# pw userdel user -r [enter]
[root@server /usr/home/user]#

Testing Connectivity

First check that you have the right version of smbclient by running:

[root@server /usr/home/user]# /usr/local/bin/smbclient --version
Version 4.6.4
[root@server /usr/home/user]#

This should show you a version starting with “Version 4.6.x”.

Now run this command access a shares on your server:

[root@server /usr/home/user]# /usr/local/bin/smbclient -U user -I localhost //localhost/public [enter]
Enter EXAMPLE\user's password: <-- user password and [enter]
Domain=[EXAMPLE] OS=[] Server=[]
smb: \>

Enter help to display a list of command:

smb: \> help [enter]
?              allinfo        altname        archive        backup
blocksize      cancel         case_sensitive cd             chmod
chown          close          del            dir            du
echo           exit           get            getfacl        geteas
hardlink       help           history        iosize         lcd
link           lock           lowercase      ls             l
mask           md             mget           mkdir          more
mput           newer          notify         open           posix
posix_encrypt  posix_open     posix_mkdir    posix_rmdir    posix_unlink
posix_whoami   print          prompt         put            pwd
q              queue          quit           readlink       rd
recurse        reget          rename         reput          rm
rmdir          showacls       setea          setmode        scopy
stat           symlink        tar            tarmode        timeout
translate      unlock         volume         vuid           wdel
logon          listconnect    showconnect    tcon           tdis
tid            logoff         ..             !
smb: \>

…and exit to exit:

smb: \> exit [enter]
[root@server /usr/home/user]#
Post-installation Setup and Configuration

Post-installation Setup and Configuration

This page was last modified [last-modified]

First login

As the FreeBSD server boots, informational messages are displayed on the screen and after the system finishes booting, a login prompt is displayed as in this example:

FreeBSD/amd64 (srv.local) (ttyv0)

login:

Login as user root with the password you entered during the installation:

login: root [enter]
Password: <-- password [enter]

Display current Network settings

Display the current active Network Interface settings with:

$ ifconfig -u [enter]
em0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
	options=81249b<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,VLAN_HWCSUM,LRO,WOL_MAGIC,VLAN_HWFILTER>
	ether 00:23:24:ba:1a:1b
	inet 192.168.1.21 netmask 0xffffff00 broadcast 192.168.1.255
	media: Ethernet autoselect (1000baseT <full-duplex>)
	status: active
	nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> metric 0 mtu 16384
	options=680003<RXCSUM,TXCSUM,LINKSTATE,RXCSUM_IPV6,TXCSUM_IPV6>
	inet6 ::1 prefixlen 128
	inet6 fe80::1%lo0 prefixlen 64 scopeid 0x2
	inet 127.0.0.1 netmask 0xff000000
	groups: lo
	nd6 options=21<PERFORMNUD,AUTO_LINKLOCAL>
$

In this example, Network Interface Controller, NIC, em0 has been found and it has been configured to have IP Address 192.168.1.21.

Remote login

To make life easier and permit you to copy commands from this web page go to another computer connected to the same local network as your FreeBSD server.

Start for example PuTTY on a Windows PC, Terminal on a Mac or a similar application on a Linux PC. In this example Terminal on a Mac is used.

Mac:~ user$ ssh user@192.168.1.21 [enter]

N.B.: The use of an SSH client is highly recommended for logging into the remote FreeBSD server!

ssh (SSH client) is a program for logging into a remote machine and for executing commands on a remote machine. It is intended to provide secure encrypted communications between two untrusted hosts over an insecure network.

N.B.: If an ssh login has been performed before to the selected IP Address a warning – in this example on an iMac – will be displayed:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ECDSA key sent by the remote host is
SHA256:.....
Please contact your system administrator.
Add correct host key in /Users/user/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /Users/user/.ssh/known_hosts:1
ECDSA host key for 192.168.1.21 has changed and you have requested strict checking.
Host key verification failed.
user@Users-iMac ~ %

On a Mac, use the following steps to get access to the hidden file known_hosts:

  1. Select and Copy the file name in the warning messag, in this example: /Users/user/.ssh/known_hosts
  2. Click on the Finder icon and verify that Finder is displayed next to the Apple icon
  3. Click on Go and then Go to folder…
  4. Click in the Go to the folder: field, past file name into it and then click button Go

A Finder window with file known_hosts should now be displayed on the screen.

Dubble-click known_hosts to open the file in TextEdit. Delete the offending line, save the file, quit TextEdit, and finally repeat the login command above.

The authenticity of host 'srv.local (192.168.1.21)' can't be established.
ECDSA key fingerprint is SHA256:...
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes [enter]
Warning: Permanently added 'srv.local' (ECDSA) to the list of known hosts.
Password for user@srv.local: <-- passwd [enter]
FreeBSD 12.2-RELEASE r366954 GENERIC 

Welcome to FreeBSD!

Release Notes, Errata: https://www.FreeBSD.org/releases/
Security Advisories:   https://www.FreeBSD.org/security/
FreeBSD Handbook:      https://www.FreeBSD.org/handbook/
FreeBSD FAQ:           https://www.FreeBSD.org/faq/
Questions List: https://lists.FreeBSD.org/mailman/listinfo/freebsd-questions/
FreeBSD Forums:        https://forums.FreeBSD.org/

Documents installed with the system are in the /usr/local/share/doc/freebsd/
directory, or can be installed later with:  pkg install en-freebsd-doc
For other languages, replace "en" with a language code like de or fr.

Show the version of FreeBSD installed:  freebsd-version ; uname -a
Please include that output and any error messages when posting questions.
Introduction to manual pages:  man man
FreeBSD directory layout:      man hier

Edit /etc/motd to change this login announcement.
If you have a CD-ROM drive in your machine, you can make the CD-ROM that is
presently inserted available by typing 'mount /cdrom' as root.  The CD-ROM
will be available under /cdrom/.  Remember to do 'umount /cdrom' before
removing the CD-ROM (it will usually not be possible to remove the CD-ROM
without doing this.)

Note: This tip may not work in all configurations.
user@server:~ $

sudo

The best practice is to never log in as the root superuser interactively. If you do – you are doing it wrong!

sudo is a program that allows a permitted user to execute a command as the superuser or another user, as specified by the user’s security policy. Unlike the su utility, sudo authenticates the user against the user’s own password rather than that of the target user. Sudo allows a system administrator to delegate authority to give certain users (or groups of users) the ability to run some (or all) commands as root or another user while providing an audit trail of the commands and their arguments. This allows the delegation of specific commands to specific users on specific systems without sharing passwords among the users.

Installation

Installation and configuration of sudo requires superuser privileges. This sudo installation will be the only and last interactive login as the root superuser you will ever need to perform on this system.

Substitute User identity to the root superuser identity with:

user@server:~ $ su -
Password: <-- passwd [enter]
root@server:~ #

Install sudo with:

root@server:~ # pkg install sudo [enter]
The package management tool is not yet installed on your system.
Do you want to fetch and install it now? [y/N]: y [enter]
Bootstrapping pkg from pkg+http://pkg.FreeBSD.org/FreeBSD:12:amd64/quarterly, please wait...
Verifying signature with trusted certificate pkg.freebsd.org.2013102301... done
Installing pkg-1.15.10...
Extracting pkg-1.15.10: 100%
Updating FreeBSD repository catalogue...
Fetching meta.conf: 100%    163 B   0.2kB/s    00:01    
Fetching packagesite.txz: 100%    6 MiB   1.1MB/s    00:06    
Processing entries: 100%
FreeBSD repository update completed. 31737 packages processed.
All repositories are up to date.
Updating database digests format: 100%
The following 3 package(s) will be affected (of 0 checked):

New packages to be INSTALLED:
	gettext-runtime: 0.21
	indexinfo: 0.3.1
	sudo: 1.9.3p1

Number of packages to be installed: 3

The process will require 5 MiB more space.
1 MiB to be downloaded.

Proceed with this action? [y/N]: y [enter]
[1/3] Fetching sudo-1.9.3p1.txz: 100%  925 KiB 473.4kB/s    00:02    
[2/3] Fetching gettext-runtime-0.21.txz: 100%  165 KiB 168.9kB/s    00:01    
[3/3] Fetching indexinfo-0.3.1.txz: 100%    6 KiB   5.8kB/s    00:01    
Checking integrity... done (0 conflicting)
[1/3] Installing indexinfo-0.3.1...
[1/3] Extracting indexinfo-0.3.1: 100%
[2/3] Installing gettext-runtime-0.21...
[2/3] Extracting gettext-runtime-0.21: 100%
[3/3] Installing sudo-1.9.3p1...
[3/3] Extracting sudo-1.9.3p1: 100%
root@server:~ #

Configuration

A default sudo configuration file /usr/local/etc/sudoers was created as part of the installation process.

N.B.: /usr/local/etc/sudoers MUST be edited with the visudo command as root.

The use of visudo minimizes the risk for syntax or file permission errors that prevents sudo from running.

Start editing file /usr/local/etc/sudoers with:

root@server:~ # visudo [enter]
## sudoers file.
##
## This file MUST be edited with the 'visudo' command as root.
## Failure to use 'visudo' may result in syntax or file permission errors
## that prevent sudo from running.
##
## See the sudoers man page for the details on how to write a sudoers file.
##
.
.
.

visudo use the famous vi editor commands. The following commands is needed for updating and saving or exit without saving file /usr/local/etc/sudoers:

  1. Use the arrow keys to move the cursor or…
  2. Move the cursor up one line with key ‘K’, down one line with key ‘J’, left one character with key ‘H’ and right one character with key ‘L’
  3. Press key ‘I’ to start inserting charters before the current cursor location
  4. Press key ‘A’ to start inserting charters after the current cursor location
  5. Press key ‘esc’ to abort inserting charters
  6. Press key ‘X’ to delete the character under the cursor
  7. Press key ‘:’, then ‘W’ and ‘Q’ to save and exit
  8. Press key ‘:’, then ‘Q’ and ‘!’ to exit without saving

To delegate privileges to the example user user locate section User privilege specification in the file /usr/local/etc/sudoers.

To allow user user to execute any command via sudo add the following text:

##
## User privilege specification
##
root ALL=(ALL) ALL
user ALL=(ALL) ALL

…or to allow user user as a members of group wheel to execute any command via sudo uncomment – delete the ‘#’ character. The line should look like this:

## Uncomment to allow members of group wheel to execute any command
%wheel ALL=(ALL) ALL

Finally exit the root superuser identity with:

root@server:~ # exit [enter]
logout
$

Date and Time

Enable superuser privileges with:

$ sudo -s [enter]

We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.

Password: <-- passwd [enter]
#

Stop the ntpd daemon program if it is running with:

# service ntpd stop [enter]
Stopping ntpd.
Waiting for PIDS: 647.
#

Set the date and time via NTP, using this command:

# ntpdate -v -b pool.ntp.org [enter]
14 Feb 14:11:07 ntpdate[831]: ntpdate 4.2.8p8-a (1)
14 Feb 14:11:15 ntpdate[831]: step time server 79.138.40.123 offset 0.001542 sec
#

N.B.: The ntp server “pool.ntp.org” is recommended by ntp.org. You can also select another one, check out http://www.ntp.org for details.

Defaults

List defaults for ntpd with:

# cat /etc/defaults/rc.conf | grep ntpd_ [enter]
ntpd_enable="NO" # Run ntpd Network Time Protocol (or NO).
ntpd_program="/usr/sbin/ntpd" # path to ntpd, if you want a different one.
ntpd_config="/etc/ntp.conf" # ntpd(8) configuration file
ntpd_sync_on_start="NO" # Sync time on ntpd startup, even if offset is high
ntpd_flags="-p /var/run/ntpd.pid -f /var/db/ntpd.drift" # Flags to ntpd (if enabled).
#

Enable NTPd

To ensure the NTP server is started at boot time verify that line ntpd_enable=”YES” to has been added to file /etc/rc.conf with:

# echo '' >> /etc/rc.conf; echo '# Network Time Protocol' >> /etc/rc.conf [enter]
# echo 'ntpd_enable="YES"' >> /etc/rc.conf [enter]
# echo 'ntpd_sync_on_start="YES"' >> /etc/rc.conf [enter]
# echo 'ntpd_flags="-p /var/run/ntpd.pid -f /var/db/ntpd.drift -g"' >> /etc/rc.conf [enter]
#

If ntpd daemon program was running and stoped without any warnings or error above, then you should edit file /etc/rc.conf with:

# ee /etc/rc.conf [enter]

…and delete line ntpd_enable=”YES” above line # Network Time Protocol.

Configure NTPd

The /etc/ntp.conf configuration file is read at initial startup by the ntpd(8) daemon in order to specify the synchronization sources, modes and other related information.

Specify the NTP synchronization sources your server will use with:

# ee /etc/ntp.conf [enter]

The following three servers will give you a random set of three NTP servers geographically close to you:

##
# ntpd.conf
#
server 0.freebsd.pool.ntp.org iburst
server 1.freebsd.pool.ntp.org iburst
server 2.freebsd.pool.ntp.org iburst

restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery
restrict 127.0.0.1
restrict -6 ::1
restrict 127.127.1.0

leapfile "/etc/ntp/leap-seconds"

See http://www.pool.ntp.org/ for details.

Example: Sweden — se.pool.ntp.org:

#
# ntpd.conf
#
server 0.se.pool.ntp.org iburst
server 1.se.pool.ntp.org iburst
server 2.se.pool.ntp.org iburst
server 3.se.pool.ntp.org iburst

restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery
restrict 127.0.0.1
restrict -6 ::1
restrict 127.127.1.0

leapfile "/etc/ntp/leap-seconds"

The driftfile is by default /var/db/ntpd.drift.

Manually start NTPd

Start Network Time Protocol (NTP) daemon, using this command:

# service ntpd start [enter]
Starting ntpd.
#

NTP is a very cautious standard. It will report its stratum to 16 (the worst possible) until it’s sure that its in sync. This can take a few minutes to few hours.

Standard NTP query program

The ntpq utility is used to monitor NTP daemon ntpd operations and determine performance.

Print a list of the peers known to the server as well as a summary of their state:

# ntpq -pn localhost [enter]
remote refid st t when poll reach delay offset jitter
==============================================================================
-188.126.88.9 192.36.144.22 2 u 22 64 1 20.184 1.962 3.454
*192.36.143.130 .PPS. 1 u 26 64 3 18.953 8.415 27.720
+194.71.144.71 192.36.144.22 2 u 31 64 3 32.755 8.158 28.261
+83.168.200.199 192.36.143.154 2 u 28 64 3 15.500 7.787 27.919
#

N.B.: Waiting for “st” to drop to 2 (since those should be stratum 2 servers) before the server is used for time sync of local computers.

Documentation

Documentation in HTML format for the NTP server can be found in: /usr/share/doc/ntp/.

Base System Binary Update

The freebsd-update tool is used to fetch, install, and rollback binary updates to the FreeBSD base system.

Fetch

Fetch files necessary for upgrading to a new release with:

# freebsd-update fetch < enter>
src component not installed, skipped
Looking up update.FreeBSD.org mirrors... 4 mirrors found.
Fetching public key from update6.freebsd.org... done.
Fetching metadata signature for 11.0-RELEASE from update6.freebsd.org... done.
Fetching metadata index... done.
Fetching 2 metadata files... done.
Inspecting system... done.
Preparing to download files... done.
Fetching 171 patches.....10....20....30....40....50....60....70....80....90....100....110....120....130....140....150....160....170 done.
Applying patches... done.
Fetching 6 files... done.
--More--(END)

Press key ‘Q’ to skip displaying the list of fetched files.

The following files will be removed as part of updating to 11.0-RELEASE-p7:
/usr/share/zoneinfo/America/Santa_Isabel
/usr/share/zoneinfo/Asia/Rangoon
--More--(END)

Press ‘space’ key to displaying a list of files that will be added.

The following files will be added as part of updating to 11.0-RELEASE-p7:
/usr/share/zoneinfo/Asia/Barnaul
/usr/share/zoneinfo/Asia/Famagusta
/usr/share/zoneinfo/Asia/Tomsk
/usr/share/zoneinfo/Asia/Yangon
/usr/share/zoneinfo/Europe/Astrakhan
/usr/share/zoneinfo/Europe/Kirov
/usr/share/zoneinfo/Europe/Ulyanovsk
--More--(END)

Press key ‘Q’ to skip displaying a list of files that will be updated.

#

Installation

The binary updates is installed with:

# freebsd-update install [enter]
src component not installed, skipped
Installing updates... done.
#

BASH – Bourne Again SHell

Bash is the GNU Project’s Bourne Again SHell, a complete implementation of the POSIX.2 shell spec, but also with interactive command line editing, job control on architectures that support it, csh-like features such as history substitution and brace expansion, and a slew of other features.

WWW: http://cnswww.cns.cwru.edu/~chet/bash/bashtop.html

Installation

Install bash with:

# pkg install bash [enter]
Updating FreeBSD repository catalogue...
Fetching meta.txz: 100% 944 B 0.9kB/s 00:01
Fetching packagesite.txz: 100% 6 MiB 2.0MB/s 00:03
Processing entries: 100%
FreeBSD repository update completed. 25860 packages processed.
The following 1 package(s) will be affected (of 0 checked):

New packages to be INSTALLED:
bash: 4.4.12

Number of packages to be installed: 1

The process will require 8 MiB more space.
1 MiB to be downloaded.

Proceed with this action? [y/N]: y [enter]
Fetching bash-4.4.12.txz: 100% 1 MiB 730.5kB/s 00:02
Checking integrity... done (0 conflicting)
[1/1] Installing bash-4.4.12...
[1/1] Extracting bash-4.4.12: 100%
Message from bash-4.4.12:
======================================================================

bash requires fdescfs(5) mounted on /dev/fd

If you have not done it yet, please do the following:

mount -t fdescfs fdesc /dev/fd

To make it permanent, you need the following lines in /etc/fstab:

fdesc /dev/fd fdescfs rw 0 0

======================================================================
#

Configuration

# mount -t fdescfs fdesc /dev/fd [enter]
#

Make this mount permanent with:

Start editing file /etc/fstab with;

# echo 'fdesc /dev/fd fdescfs rw 0 0' >> /etc/fstab
#

Change the current user’s shell setting to bash with:

# chsh -s /usr/local/bin/bash user [enter]
chsh: user information updated
# chsh -s /usr/local/bin/bash root [enter]
chsh: user information updated
#

Verify that bash is the default shell for user account user, with:

# cat /etc/passwd | grep user
.
.
.
user:*:1001:1001:Example User:/home/user:/usr/local/bin/bash
.
.
#

Verify that bash is the default shell for user account root, with:

# cat /etc/passwd | grep root
.
.
root:*:0:0:Charlie &:/root:/usr/local/bin/bash
.
.
#

Optional: Colorized ‘ls’ and ‘ll’ in BASH

Description

Enable ls color and add command ll with some color.

Configuration

Add two alias commands to file /etc/profile for all users with:

# echo "alias ll='ls -lGF'" >> /etc/profile; echo "alias ls='ls -GF'" >> /etc/profile [enter]
#

Revoke Privileges

Revoke superuser privileges with:

# exit [enter]
$

Log off your system with:

$ exit [enter]

Log Console Messages to File

Messages printed to the console during boot will pass by too fast to be read, or are too long to be copied.

Login to your system via a remote ssh session.

Enable superuser privileges with:

[user@server ~]$ sudo -s [enter]
[root@server /usr/home/user]#

Enable all writes to /dev/console to be logged to file /var/log/console.log with:

[root@server /usr/home/user]# ee /etc/syslog.conf [enter]

…and then uncomment line 21 as in this example:

console.info /var/log/console.log

Create file /var/log/console.log with:

[root@server /usr/home/user]# touch /var/log/console.log [enter]
[root@server /usr/home/user]#

…and then change file modes to mode 600 with:

[root@server /usr/home/user]# chmod 600 /var/log/console.log [enter]
[root@server /usr/home/user]#

Restart syslogd to log all new console messages to file /var/log/console.log with:

[root@server /usr/home/user]# service syslogd restart [enter]
Stopping syslogd.
Waiting for PIDS: 808.
Starting syslogd.
[root@server /usr/home/user]#

A reboot is required to record all console messages on system boot. Reboot the system with:

[root@server /usr/home/user]# reboot [enter]

Wait for system to reboot and the log back in with a remote ssh client session.

Enable superuser privileges with:

[user@server ~]$ sudo -s [enter]
[root@server /usr/home/user]#

Display file /var/log/console.log with:

[root@server /usr/home/user]# cat /var/log/console.log [enter]

…and look for ERRORs and WARNINGs as in this example:

.
.
Jan 14 15:51:11 server kernel: WARNING:
Jan 14 15:51:11 server kernel: New keymap: In /etc/rc.conf replace 'keymap=swedish.cp850.kbd' by 'keymap=se'.
.
.

If any errors and warnings is found, fix the problem and restart service syslogd as described above.

N.B.: The error displayed above has been fixed in the /etc/rc.conf example below!

Packet Filter (PF) Firewall

This PF setup is configured be very secure. All attempts to access the server via the network is blocked on all network ports with one critical exception; ssh clients on the local network using port 123 can access to allow for management of the headless server.

The example setup is designed to be used on a Headless Server with a single network interface card connected to a local network behind a firewall for internet access.

List LAN Network Card

List status up network interfaces with:

[root@server /usr/home/user]# ifconfig -u [enter]
em0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
options=4019b<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,VLAN_HWCSUM,TSO4,VLAN_HWTSO>
ether xx:xx:xx:xx:xx:xx
inet 192.168.1.114 netmask 0xffffff00 broadcast 192.168.1.255
nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>
media: Ethernet autoselect (1000baseT <full-duplex>)
status: active
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> metric 0 mtu 16384
options=600003<RXCSUM,TXCSUM,RXCSUM_IPV6,TXCSUM_IPV6>
inet6 ::1 prefixlen 128
inet6 fe80::1%lo0 prefixlen 64 scopeid 0x2
inet 127.0.0.1 netmask 0xff000000
nd6 options=21<PERFORMNUD,AUTO_LINKLOCAL>
groups: lo
[root@server /usr/home/user]#

In this example Network Interface Card em0 will be used.

Packet Filter (pf) Config File

Create file /etc/pf.conf with:

[root@server /usr/home/user]# ee /etc/pf.conf [enter]

…and copy this text to the file:

################ FreeBSD pf.conf ##########################################
# Required order: options, normalization, queueing, translation, filtering.
# Note: translation rules are first match while filter rules are last match.
################ Macros ####################################################

# Macros
lan_if="em0" # Local Network Interface Card

# Ports:
# 123 TCP Network Time Protocol

tcp_pass="{ 123 }"

# Tables

### Options
set block-policy return

### Normalization
scrub on $lan_if all random-id reassemble tcp fragment reassemble

### Queueing

### Translation

### Filtering

# Skip filtering on loopback
set skip on lo0

# Block traffic trying to get into the loopback interface from outside.
block quick from any to lo0:network

# Block all traffic in on LAN NIC by default
block in on $lan_if

# Pass specified traffic in to this server from LAN clients
pass in on $lan_if proto tcp from $lan_if:network to $lan_if port $tcp_pass

# Pass SSH traffic from LAN clients (for Admin)
pass in on $lan_if proto tcp from $lan_if:network to $lan_if port ssh

# Pass icmp (for ping) on LAN NIC
pass in on $lan_if proto icmp

# Pass all traffic out on LAN NIC by default
pass out on $lan_if proto { tcp, udp, icmp } all

N.B.: Update lan_if=”em0″ to match your systems LAN Internet Network Card ID!

Display the default packet filter (pf) and packet filter logging (pflog) settings with:

[root@server /usr/home/user]# cat /etc/defaults/rc.conf | grep -e "pf_\|pflog_" [enter]
pf_enable="NO" # Set to YES to enable packet filter (pf)
pf_rules="/etc/pf.conf" # rules definition file for pf
pf_program="/sbin/pfctl" # where the pfctl program lives
pf_flags="" # additional flags for pfctl
pflog_enable="NO" # Set to YES to enable packet filter logging
pflog_logfile="/var/log/pflog" # where pflogd should store the logfile
pflog_program="/sbin/pflogd" # where the pflogd program lives
pflog_flags="" # additional flags for pflogd
[root@server /usr/home/user]#

Service start on Boot

List installed pf services with:

[root@server /usr/home/user]# service -r | grep /pf [enter]
/etc/rc.d/pfsync
/etc/rc.d/pflog
/etc/rc.d/pf
[root@server /usr/home/user]#

Find the rcvar for /etc/rc.d/pf with:

[root@server /usr/home/user]# /etc/rc.d/pf rcvar [enter]
# pf : Packet filter
#
pf_enable="NO"
# (default: "")

[root@server /usr/home/user]#

..and for /etc/rc.d/pflog with:

[root@server /usr/home/user]# /etc/rc.d/pflog rcvar [enter]
# pf : Packet filter
#
pflog_enable="NO"
# (default: "")

[root@server /usr/home/user]#

Enable packet filter (pf) and packet filter logging (pflog) at boot with:

[root@server /usr/home/user]# echo '' >> /etc/rc.conf; echo '# Packet Filter (pf)' >> /etc/rc.conf; echo 'pf_enable="YES"' >> /etc/rc.conf; echo 'pflog_enable="YES"' >> /etc/rc.conf [enter]
[root@server /usr/home/user]#

Check /etc/pf.conf for errors, but do not load ruleset with:

[root@server /usr/home/user]# pfctl -vvnf /etc/pf.conf [enter]
int_if = "em0"
tcp_pass = "{ 123 }"
set block-policy return
set skip on { lo0 }
@0 scrub on em0 all random-id reassemble tcp fragment reassemble
@0 block return quick inet6 from any to ::1
@1 block return quick inet from any to 127.0.0.0/8
@2 block return in on em0 all
@3 pass in on em0 inet proto tcp from 192.168.1.0/24 to 192.168.1.5 port = ntp flags S/SA keep state
@4 pass in on em0 inet proto tcp from 192.168.1.0/24 to 192.168.1.5 port = netbios-ssn flags S/SA keep state
@5 pass in on em0 inet proto tcp from 192.168.1.0/24 to 192.168.1.5 port = microsoft-ds flags S/SA keep state
@6 pass in on em0 inet proto tcp from 192.168.1.0/24 to 192.168.1.5 port = ssh flags S/SA keep state
@7 pass in on em0 proto icmp all keep state
@8 pass out on em0 proto tcp all flags S/SA keep state
@9 pass out on em0 proto udp all keep state
@10 pass out on em0 proto icmp all keep state
[root@server /usr/home/user]#

Manually start the packet filter (pf) with:

[root@server /usr/home/user]# service pf start [enter]
Enabling pf

N.B.: This may disconnect the current ssh connections!

If you are disconnected, open a new remote ssh terminal session to the server and enable superuser privileges with:

[user@server ~]$ sudo -s
[root@server /usr/home/user]#

If everything is alright, then you will be able to verify the packet filter (pf) status with:

[root@server /usr/home/user]# service pf status [enter]
Status: Enabled for 0 days 00:13:15 Debug: Urgent

State Table Total Rate
current entries 1
searches 222 0.3/s
inserts 1 0.0/s
removals 0 0.0/s
Counters
match 79 0.1/s
bad-offset 0 0.0/s
fragment 0 0.0/s
short 0 0.0/s
normalize 0 0.0/s
memory 0 0.0/s
bad-timestamp 0 0.0/s
congestion 0 0.0/s
ip-option 0 0.0/s
proto-cksum 14 0.0/s
state-mismatch 0 0.0/s
state-insert 0 0.0/s
state-limit 0 0.0/s
src-limit 0 0.0/s
synproxy 0 0.0/s
map-failed 0 0.0/s
[root@server /usr/home/user]#

N.B.: Verify that the pf status is Enabled as in the example above.

Reload updates to /etc/pf.conf file with:

[root@server /usr/home/user]# service pf reload [enter]
[root@server /usr/home/user]#

…or load another file – in this example file /etc/pf.new – with:

[root@server /usr/home/user]# pfctl -vf /etc/pf.new [enter]
[root@server /usr/home/user]#

To see in real-time who is trying to connect to your server:

[root@server /usr/home/user]# tcpdump -n -e -ttt -i pflog0 [enter]
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on pflog0, link-type PFLOG (OpenBSD pflog file), capture size 262144 bytes

When network activites is detected it will be listas as in this example:

00:00:00.000000 rule 28..16777216/0(match): block in on em0: 192.168.1.11.138 > 192.168.1.255.138: NBT UDP PACKET(138)
00:00:40.080628 rule 28..16777216/0(match): block in on em0: 192.168.1.11.137 > 192.168.1.255.137: NBT UDP PACKET(137): QUERY; REQUEST; BROADCAST
00:00:25.057112 rule 28..16777216/0(match): block in on em0: 192.168.1.127.138 > 192.168.1.255.138: NBT UDP PACKET(138)
00:01:00.244084 rule 28..16777216/0(match): block in on em0: 192.168.1.10.137 > 192.168.1.255.137: NBT UDP PACKET(137): QUERY; REQUEST; BROADCAST
00:00:13.685497 rule 28..16777216/0(match): block in on em0: 192.168.1.124.137 > 192.168.1.255.137: NBT UDP PACKET(137): QUERY; REQUEST; BROADCAST
00:00:00.749718 rule 28..16777216/0(match): block in on em0: 192.168.1.124.137 > 192.168.1.255.137: NBT UDP PACKET(137): QUERY; REQUEST; BROADCAST
00:00:00.096546 rule 28..16777216/0(match): block in on em0: 192.168.1.124.137 > 192.168.1.255.137: NBT UDP PACKET(137): QUERY; REQUEST; BROADCAST
00:00:00.653724 rule 28..16777216/0(match): block in on em0: 192.168.1.124.137 > 192.168.1.255.137: NBT UDP PACKET(137): QUERY; REQUEST; BROADCAST
00:00:00.093843 rule 28..16777216/0(match): block in on em0: 192.168.1.124.137 > 192.168.1.255.137: NBT UDP PACKET(137): QUERY; REQUEST; BROADCAST
00:00:00.750227 rule 28..16777216/0(match): block in on em0: 192.168.1.124.137 > 192.168.1.255.137: NBT UDP PACKET(137): QUERY; REQUEST; BROADCAST

Hit [ ctr ] and [ C ] to abort.

^C
10 packets captured
10 packets received by filter
0 packets dropped by kernel
[root@server /usr/home/user]#

In this example a HP LaserJet printer is broadcasting UDB packages, port 137 – ‘NetBIOS Name Service, used for name registration and resolution’ – and port 138 – ‘NetBIOS Datagram Service’.

Show history:

[root@server /usr/home/user]# tcpdump -n -e -ttt -r /var/log/pflog [enter]

And that’s it. You have successfully implemented PF firewall on your FreeBSD server!

Configuration Files

/etc/rc.conf

The file rc.conf contains descriptive information about the local host name, configuration details for any potential network interfaces and which services should be started up at system initial boot time. In new installations, the rc.conf file is generally initialized by the system installation utility.

[root@server /usr/home/user]# cat /etc/rc.conf [enter]

Example: When option < Yes >, use DHCP, was selected in the Network Configuration dialog.

clear_tmp_enable="YES"
sendmail_enable="NONE"
hostname="server.example.net"
keymap="se"
ifconfig_em0="DHCP"
sshd_enable="YES"
# Set dumpdev to "AUTO" to enable crash dumps, "NO" to disable
dumpdev="NO"
zfs_enable="YES"
# ahci Advanced Host Controller Interface (AHCI)
# coretemp Device driver for Intel Core on-die digital thermal sensor
# i915kms Intel Graphics
kld_list="ahci coretemp i915kms"

# Network Time Protocol
ntpd_enable="YES"
ntpd_sync_on_start="YES"
ntpd_flags="-p /var/run/ntpd.pid -f /var/db/ntpd.drift -g"

# Packet Filter (pf)
pf_enable="YES"
pflog_enable="YES"

Example: When option < No >, use DHCP, was selected in the Network Configuration dialog.

clear_tmp_enable="YES"
sendmail_enable="NONE"
hostname="server.example.net"
keymap="se"
ifconfig_em0="inet 192.168.1.4 netmask 255.255.255.0"
defaultrouter="192.168.1.1"
sshd_enable="YES"
# Set dumpdev to "AUTO" to enable crash dumps, "NO" to disable
dumpdev="NO"
zfs_enable="YES"

# Network Time Protocol
ntpd_enable="YES"
ntpd_sync_on_start="YES"
ntpd_flags="-p /var/run/ntpd.pid -f /var/db/ntpd.drift -g"

# ahci Advanced Host Controller Interface (AHCI)
# coretemp Device driver for Intel Core on-die digital thermal sensor
# i915kms Intel Graphics
kld_list="ahci coretemp i915kms"

# Packet Filter (pf)
pf_enable="YES"
pflog_enable="YES"

Information will be added as required by programs and services installed on the system.

The ifconfig_em0 entry in the example file above

/boot/loader.conf

The file loader.conf contains descriptive information on bootstrapping the system. Through it you can specify the kernel to be booted, parameters to be passed to it, and additional modules to be loaded; and generally set all variables described in loader(8).

[root@server /usr/home/user]# cat /boot/loader.conf

Example: New installation of FreeBSD.

kern.geom.label.disk_ident.enable="0"
kern.geom.label.gptid.enable="0"
vfs.zfs.min_auto_ashift=12
zfs_load="YES"

Example: Modules and parameters added for a Intel HW based FreeBSD Server.

kern.geom.label.disk_ident.enable="0"
kern.geom.label.gptid.enable="0"
vfs.zfs.min_auto_ashift=12
zfs_load="YES"

# How many seconds to sit at the boot menu before booting
autoboot_delay="3"

# Use new graphical consol driver
kern.vty="vt"
hw.vga.textmode=1

# Displayed the colored Beastie logo to the right of the boot options menu
loader_logo="beastie"

Optional: Add Local User

The adduser utility is a shell script, implemented around the pw(8) command, for adding new users.

N.B.: Remember to invite the user into other group wheel to enable this user login remotely via a ssh client!

Create a new local user for remote login with:

[root@server /usr/home/user]# sudo adduser [enter]
Password: <-- passwd [enter]
Username: username [enter]
Full name: Full Name [enter]
Uid (Leave empty for default):
Login group [username]:
Login group is username. Invite username into other groups? []: wheel [enter]
Login class [default]:
Shell (sh csh tcsh nologin) [sh]:
Home directory [/home/username]:
Home directory permissions (Leave empty for default):
Use password-based authentication? [yes]:
Use an empty password? (yes/no) [no]:
Use a random password? (yes/no) [no]:
Enter password:
Enter password again:
Lock out the account after creation? [no]:
Username : username
Password : *****
Full Name : Full Name
Uid : 1001
Class :
Groups : username wheel
Home : /home/username
Home Mode :
Shell : /bin/sh
Locked : no
OK? (yes/no): yes [enter]
adduser: INFO: Successfully added (username) to the user database.
Add another user? (yes/no): no [enter]
Goodbye!
[root@server /usr/home/user]#

Completion of Basic Installation

Power off the server with:

[root@server /usr/home/user]# poweroff [enter]

Wait for the server to perform power off, disconnect the monitor and the keyboard and then start the server again.

That’s it!

Your FreeBSD Headless Server is now ready for the next step, installation of services and utilities to fulfill your need of a secure and reliable local data and web server for your home or small office.

Create a USB Memory Stick for installation of FreeBSD 13.1-RELEASE-amd64

Create a USB Memory Stick for installation of FreeBSD 13.1-RELEASE-amd64

This page was last updated [last-modified]

A USB Memory Stick can be prepared to install FreeBSD 13.1-RELEASE.amd64 on a computer with Internet access running FreeBSD, MacOS, Linux, or Microsoft Windows.

FreeBSD

Requirements:

Required hardware: USB Memory Stick, minimum size 2 GB

Required software: sudo, wget

sudo allows a permitted user to execute a command as the superuser or another user, as specified by the security policy.

GNU wget is a free utility for non-interactive download of files from the Web. It supports HTTP, HTTPS, and FTP protocols, as well as retrieval through HTTP proxies.

Download the FreeBSD image file

Start a terminal session to or on the FreeBSD Computer.

Download the FreeBSD-13.1-RELEASE-amd64-memstick.img image, 736 MByte, with:

[user@freebsd ~]$ wget wget https://download.freebsd.org/ftp/releases/ISO-IMAGES/13.1/FreeBSD-13.1-RELEASE-amd64-memstick.img --no-check-certificate -P ~/ [enter]

Download the CHECKSUM.SHA512-FreeBSD-13.1-RELEASE-amd64 image, 1.8 kByte, with:

[user@freebsd ~]$ wget https://download.freebsd.org/ftp/releases/ISO-IMAGES/13.1/CHECKSUM.SHA512-FreeBSD-13.1-RELEASE-amd64 --no-check-certificate -P ~/ [enter]

Calculate the checksum for the file with:

[user@freebsd ~]$ shasum -a 512 Downloads/FreeBSD-13.1-RELEASE-amd64-memstick.img [enter]
d4c58df629c7db6bf2ee2d43ae7f7b9e1c8b98fca0b89dd1afa1bed21891ecc2  /root/FreeBSD-13.1-RELEASE-amd64-memstick.img
root@server:~ #

…and compare the result with the checksum in file CHECKSUM.SHA512-FreeBSD-13.1-RELEASE-amd64 with:

[user@freebsd ~]$ cat Downloads/CHECKSUM.SHA512-FreeBSD-13.1-RELEASE-amd64 | grep
dbe066cb726b375eebca397aff12d18d6e48ad6c84b776253aabc2bbdff8fb9742e17fb68356581b0b20709002fdf9c3c77eccfd9c0c745e8f93a830264148a5 [enter]
SHA512 (FreeBSD-13.1-RELEASE-amd64-mini-memstick.img.xz) = dbe066cb726b375eebca397aff12d18d6e48ad6c84b776253aabc2bbdff8fb9742e17fb68356581b0b20709002fdf9c3c77eccfd9c0c745e8f93a830264148a5
user@server:~ #

Copy the FreeBSD image file to the USB Memory Stick

Insert the USB Memory Stick to a USB Port on the FreeBSD Computer.

N.B.: All Data on the USB Memory Stick will be lost!

Since USB devices are seen as a SCSI devices, camcontrol can be used to list device information for the inserted USB Memory Stick with this command:

[user@freebsd ~]$ sudo camcontrol devlist [enter]
Password: <-- passwd [enter] 
<ST1000DM010-2EP102 CC43>          at scbus2 target 0 lun 0 (pass0,ada0)
<AHCI SGPIO Enclosure 1.00 0001>   at scbus6 target 0 lun 0 (pass1,ses0)
<SanDisk Cruzer 7.01>              at scbus7 target 0 lun 0 (da0,pass2)
[user@freebsd ~]$

…or show the list with:

[user@freebsd ~]$ geom disk list [enter]
Geom name: cd0
Providers:
1. Name: cd0
   Mediasize: 0 (0B)
   Sectorsize: 2048
   Mode: r0w0e0
   descr: TSSTcorp DVD+-RW TS-L633A
   ident: (null)
   rotationrate: unknown
   fwsectors: 0
   fwheads: 0

Geom name: ada0
Providers:
1. Name: ada0
   Mediasize: 750156374016 (699G)
   Sectorsize: 512
   Stripesize: 4096
   Stripeoffset: 0
   Mode: r2w2e3
   descr: WDC WD7500BPKT-75PK4T0
   lunid: 50014ee2059f311c
   ident: WD-WXD1EC0PZ269
   rotationrate: 7200
   fwsectors: 63
   fwheads: 16

Geom name: da0
Providers:
1. Name: da0
   Mediasize: 8036285952 (7.5G)
   Sectorsize: 512
   Mode: r0w0e0
   descr: SanDisk Cruzer
   ident: 2444630C9FC0D053
   rotationrate: unknown
   fwsectors: 63
   fwheads: 255

[user@freebsd ~]$

In this example, SanDisk Cruzer 7.01 registered as device da0 is the target USB Memory Stick.

Optional: Display information about device da0 with, example:

[user@freebsd ~]$ diskinfo -v da0 [enter]
da0
	512         	# sectorsize
	8036285952  	# mediasize in bytes (7.5G)
	15695871    	# mediasize in sectors
	0           	# stripesize
	0           	# stripeoffset
	977         	# Cylinders according to firmware.
	255         	# Heads according to firmware.
	63          	# Sectors according to firmware.
	2444630C9FC0D053	# Disk ident.
	Not_Zoned   	# Zone Mode

[user@freebsd ~]$

Optional: Show the current partition information of the USB Memory Stick using this command:

[user@freebsd ~]$ gpart show da0 [enter]
=>      63  15695808  da0  MBR  (7.5G)
        63      1985       - free -  (993K)
      2048  15693823    1  !12  (7.5G)

[user@freebsd ~]$

N.B.: Your USB Memory Stick may have a different layout than in this example!

WARNING: The next step will delete all information on the USB Memory Stick!

Destroy the partitioning scheme on the USB Memory Stick with:

[user@freebsd ~]$ sudo gpart destroy -F da0 [enter]
Password: <-- passwd [enter]
da0 destroyed
[user@freebsd ~]$

The image file FreeBSD-13.1-RELEASE-amd64-memstick.img is copied to the USB Memory Stick with the dd utility with this command:

[user@freebsd ~]# sudo dd if=FreeBSD-13.1-RELEASE-amd64-memstick.img of=/dev/da0 bs=1m [enter]
Password: <-- passwd [enter]

When the copy process has been completed, a summary of the process will be displayed as in this example:

738+1 records in
738+1 records out
774215168 bytes transferred in 88.733136 secs (8725209 bytes/sec)
[user@freebsd ~]$

Delete FreeBSD-13.1-RELEASE-amd64-memstick.img file with:

[user@freebsd ~]# rm FreeBSD-13.1-RELEASE-amd64-memstick.img [enter]
rm CHECKSUM.SHA512-FreeBSD-13.1-RELEASE-amd64 [enter]
[user@freebsd ~]#

Disconnect the USB Memory Stick.

MacOS

Requirements:

Required hardware: USB Memory Stick, minimum size 2 GB

Required software: None

Download files

Click on https://download.freebsd.org/ftp/releases/ISO-IMAGES/13.1/FreeBSD-13.1-RELEASE-amd64-memstick.img to download the image file FreeBSD-13.1-RELEASE-amd64-memstick.img.
Click on https://download.freebsd.org/ftp/releases/ISO-IMAGES/13.1/CHECKSUM.SHA512-FreeBSD-13.1-RELEASE-amd64 to download the checksum file CHECKSUM.SHA512-FreeBSD-13.1-RELEASE-amd64.

Verify checksum

Launch the Terminal application.
Calculate the checksum for the file with:

user@iMac ~ % shasum -a 512 Downloads/FreeBSD-13.1-RELEASE-amd64-memstick.img [enter]
96bf96628a566cb33d736315dfb56e3076ab0d757ad6c94fa2235866007f7726dc42ac2b81abd7810ae40a945220088605dbf387ebed7d688a9b80dec5253247  Downloads/FreeBSD-13.1-RELEASE-amd64-memstick.img
user@iMac ~ %

Compare the result with the checksum in file CHECKSUM.SHA512-FreeBSD-13.1-RELEASE-amd64 with:

user@iMac ~ % grep 96bf96628a566cb33d736315dfb56e3076ab0d757ad6c94fa2235866007f7726dc42ac2b81abd7810ae40a945220088605dbf387ebed7d688a9b80dec5253247 Downloads/CHECKSUM.SHA512-FreeBSD-13.1-RELEASE-amd64 [enter]
SHA512 (FreeBSD-13.1-RELEASE-amd64-memstick.img) = 96bf96628a566cb33d736315dfb56e3076ab0d757ad6c94fa2235866007f7726dc42ac2b81abd7810ae40a945220088605dbf387ebed7d688a9b80dec5253247
user@iMac ~ %

The calculated checksum for the downloaded image file should match the posted checksum in the CHECKSUM.SHA512-FreeBSD-13.1-RELEASE-amd64 file.

Copy the FreeBSD image file to the USB Memory Stick

Insert the target USB Memory Stick to a USB Port on the Macintosh Computer.

Run the diskutil list command to find out the device name of the USB disk as in this example:

user@iMac ~ % diskutil list [enter]
/dev/disk0 (internal, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *1.0 TB     disk0
   1:                        EFI EFI                     209.7 MB   disk0s1
   2:                  Apple_HFS Macintosh HD            999.3 GB   disk0s2
   3:                 Apple_Boot Recovery HD             650.0 MB   disk0s3

/dev/disk1 (external, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *8.0 GB     disk1
   1:                        EFI EFI                     819.2 KB   disk1s1
   2: 83BD6B9D-7F41-11DC-BE0B-001560B84F0F               64.0 KB    disk1s2
   3:                FreeBSD UFS                         732.1 MB   disk1s3
   4:               FreeBSD Swap                         1.0 MB     disk1s4

user@iMac ~%

In this example, /dev/disk1 is the target USB Memory Stick.

Unmount the USB Memory Stick with:

user@iMac ~% diskutil unmountDisk /dev/disk1 [enter]
Unmount of all volumes on disk1 was successful
user@iMac ~%

Use dd to raw write the image file to the /dev/disk1.

WARNING: This will delete all information on the USB Memory Stick!

N.B.: Update /dev/rdisk1 in the next commando to the /dev/rdisk-number displayde on your Mac!

user@iMac ~% sudo dd if=Downloads/FreeBSD-13.1-RELEASE-amd64-memstick.img of=/dev/rdisk1 bs=4m [enter]
Password: <-- password [enter]

When the copy process has been completed, a summary of the process will be displayed as in this example:

279+1 records in
279+1 records out
1172165120 bytes transferred in 30.176911 secs (38843112 bytes/sec)
user@iMac ~%

Delete the FreeBSD-13.1-RELEASE-amd64-memstick.img file in Your Download folder.

Disconnect the USB Memory Stick.

Linux

Requirements:

Required hardware: USB Memory Stick, minimum size 2 GB.

Required software: None

(To be completed and verified)

Microsoft Windows

Requirements:

Required hardware: USB Memory Stick, minimum size 2 GB

Required software: Rufus (Selected to be used in this example)

Rufus is a utility that helps format and creates bootable USB flash drives, such as USB keys/pendrives, memory sticks, etc.

Download the latest version of Rufus from: https://rufus.akeo.ie

Save the Rufus utility executable file in a folder or on the desktop of your computer.

N.B. No installation is necessary!

Download the FreeBSD image file

Click on https://download.freebsd.org/ftp/releases/ISO-IMAGES/13.1/FreeBSD-13.1-RELEASE-amd64-memstick.img to download image file FreeBSD-13.1-RELEASE-amd64-memstick.img.

Copy the FreeBSD image file to the USB Memory Stick

Insert the USB Memory Stick to a USB Port on the Windows Computer.

Locate and double-click the Rufus Utility executable file to start the Rufus utility.

Verify that the inserted USB Memory Stick has been detected and selected in the Rufus dialog window.

Click on the CD drive icon and select the FreeBSD-13.1-RELEASE-amd64-memstick.img image file.

WARNING: The next step will delete all information on the USB Memory Stick!

Click the button Start and wait for the process to be completed.

Delete the FreeBSD-13.1-RELEASE-amd64-memstick.img file in Your Download folder.

Disconnect the USB Memory Stick.