install Samba Server on FreeBSD 13

 

 

In this tutorial we are going to be setting up a FreeBSD file server using NFS and/or Samba. There are many reasons to use FreeBSD for a file server, a fe examples are its unmatched stability and native ZFS. We will be doing this on a fresh install of FreeBSD 13.


Preliminary:

First of all we need to do a few things to prepare our system. Fully update the system and the ports tree.

Use su to become root since this entire process will require root privileges.

vulnifo@freebsd-test:~ % su
Password:
root@freebsd-test:/home/vulnifo #

Use these commands to update FreeBSD.

# freebsd-update fetch
...
# freebsd-update install
...

If any kernel modules were updated, a reboot will be required. Do this with the following commands.

# freebsd-version -k
13.0-RELEASE-p4
# uname -r
13.0-RELEASE

Since the outputs of the two commands don’t match, we need to reboot.

# shutdown -r now

After the machine reboots we need to install the ports tree. Use the following commands

# portsnap fetch
...
# portsnap extract

Please note: If this is the first time you have run this, it is going to take a while to complete!

With an updated system and ports tree, we can start installing software.

Samba on FreeBSD:

In this section we are going to be installing and configuring samba, which is the unix/linux equivalent of Windows SMB. This software is best used when trying to share files with Microsoft Windows or MacOS, but is easily used to share files with linux OS’s as well.

Installing Samba

First, let’s search the ports tree for samba.

# pkg search samba
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.16.5          nsupdate utility with the GSS-TSIG support
samba412-4.12.15_1             Free SMB/CIFS and AD/DC server and client for Unix
samba413-4.13.8                Free SMB/CIFS and AD/DC server and client for Unix

Now we can install samba.

# pkg install samba413

...

Message from samba413-4.13.8:

--
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/

Samba Configuration

Either create a directory to share or note an existing directory that you would like shared. Change *username* to your user.

# mkdir /smbshare
# chown *username* /smbshare

Now lets edit the samba configuration file.

Use whatever text editor you like, I will use nano. (If you don’t have nano simply use the command “pkg install nano”)

# nano /usr/local/etc/smb4.conf

Add this to the file (again, change *username* to your user).

[global]
workgroup          = WORKGROUP
netbios name       = freebsd-test
server string      = samba
security           = user
wins support       = yes
passdb backend tdbsam


# Following is the data directory you want to share.

[smbshare]
  path = /smbshare
  valid users = *username*
  public = no
  writable  = yes
  browsable  = yes
  read only = no
  guest ok = no
  create mask = 0755
  directory mask = 0755

We need to create a specific samba user. This can be the same user as your system user, but still must be done to allow samba to have its own user. Note this user should match with the username used in the previous config file!

 # pdbedit -a -u vulnifo
new password:
retype new password:

Now we need to add samba to the system config and enable it.

# sysrc samba_server_enable=YES
samba_server_enable:  -> YES
# sysrc samba_server_enable
samba_server_enable: YES

Now lets make sure it made it into the rc.conf file, which is the main configuration file for FreeBSD.

# cat /etc/rc.conf

hostname="freebsd-test"
ifconfig_vtnet0="DHCP"
sshd_enable="YES"
ntpdate_enable="YES"
ntpd_enable="YES"
# Set dumpdev to "AUTO" to enable crash dumps, "NO" to disable
dumpdev="AUTO"
zfs_enable="YES"
samba_server_enable="YES"

You can see that the samba server is enabled with the bottom line. Now we can start the samba service.

# service samba_server start
Performing sanity check on Samba configuration: OK
Starting nmbd.
Starting smbd.

 

来源:https://blog.vulnifo.com/2021/09/17/how-to-setup-nfs-and-samba-on-freebsd-13/

 

posted @ 2023-03-14 13:35  profesor  阅读(74)  评论(0)    收藏  举报