読者です 読者をやめる 読者になる 読者になる

作業中のメモ

よく「計算機」を使って作業をする.知らなかったことを中心にまとめるつもり.

Raspberry Pi 3 Model B でファイルサーバーとプリンタサーバーを構築する(その 3) Samba のインストールと設定

どうも,筆者です.

前回の続きである. workspacememory.hatenablog.com

今回は,Samba のインストールとその設定を行う.

Samba のインストール

Samba のインストールは,コマンド 1 行で行える.

sudo apt-get install -y samba

外付け HDD のフォーマットとマウント

外付け HDD が正しく接続されているかを確認する.その後,パーティションの設定を行い,フォーマットする.パーティションの設定等は,Raspberry Piでファイルサーバ、Part2 外付けハードディスクの導入編 を参考にした.

# 接続確認
sudo fdisk -l
# パーティションの設定
sudo fdisk /dev/sda
# フォーマット
sudo mkfs.ext4 /dev/sda1

自動マウントのために UUID の取得とマウント先を作成し,設定を記述する.

# マウント先の生成
sudo mkdir /media/hdd1
# UUID の取得
sudo blkid /dev/sda1
# 設定を記述
sudo vim /etc/fstab

### === /etc/fstab の中身 === ###
proc            /proc           proc    defaults          0       0
/dev/mmcblk0p1  /boot           vfat    defaults          0       2
/dev/mmcblk0p2  /               ext4    defaults,noatime  0       1
UUID=abcdefgh-1234-5678-xyzw-123abc456xyz  /media/hdd1         ext4    defaults  0       0  # ここに追加
# a swapfile is not a swap partition, no line here
#   use  dphys-swapfile swap[on|off]  for that

# 再起動しておく
reboot

Samba の設定

その後,共有するディレクトリを作成する.そして,Samba の設定を行う.

pushd /media/hdd1/
# ディレクトリの生成
sudo mkdir share
sudo chown -R nobody:nogroup share
sudo chmod 777 share
popd

# Samba の設定
sudo vim /etc/samba/smb.conf
#
# Sample configuration file for the Samba suite for Debian GNU/Linux.
#
#
# This is the main Samba configuration file. You should read the
# smb.conf(5) manual page in order to understand the options listed
# here. Samba has a huge number of configurable options most of which
# are not shown in this example
#
# Some options that are often worth tuning have been included as
# commented-out examples in this file.
#  - When such options are commented with ";", the proposed setting
#    differs from the default Samba behaviour
#  - When commented with "#", the proposed setting is the default
#    behaviour of Samba but the option is considered important
#    enough to be mentioned here
#
# NOTE: Whenever you modify this file you should run the command
# "testparm" to check that you have not made any basic syntactic
# errors.

#======================= Global Settings =======================

[global]

## Browsing/Identification ###
   dos charset = CP932
   unix charset = UTF8

# Change this to the workgroup/NT-domain name your Samba server will part of
   workgroup = WORKGROUP

# Windows Internet Name Serving Support Section:
# WINS Support - Tells the NMBD component of Samba to enable its WINS Server
#   wins support = no

# WINS Server - Tells the NMBD components of Samba to be a WINS Client
# Note: Samba can be either a WINS Server, or a WINS Client, but NOT both
;   wins server = w.x.y.z

# This will prevent nmbd to search for NetBIOS names through DNS.
   dns proxy = no

#### Networking ####
   hosts deny = all
   hosts allow = 192.168.33.

# The specific set of interfaces / networks to bind to
# This can be either the interface name or an IP address/netmask;
# interface names are normally preferred
;   interfaces = 127.0.0.0/8 eth0

# Only bind to the named interfaces and/or networks; you must use the
# 'interfaces' option above to use this.
# It is recommended that you enable this feature if your Samba machine is
# not protected by a firewall or is a firewall itself.  However, this
# option cannot handle dynamic or non-broadcast interfaces correctly.
;   bind interfaces only = yes
   printing = cups
   printcap name = cups


#### Debugging/Accounting ####

# This tells Samba to use a separate log file for each machine
# that connects
   log file = /var/log/samba/log.%m

# Cap the size of the individual log files (in KiB).
   max log size = 1000                                                                                                                                                
# If you want Samba to only log through syslog then set the following
# parameter to 'yes'.
#   syslog only = no

# We want Samba to log a minimum amount of information to syslog. Everything
# should go to /var/log/samba/log.{smbd,nmbd} instead. If you want to log
# through syslog you should set the following parameter to something higher.
   syslog = 0

# Do something sensible when Samba crashes: mail the admin a backtrace
   panic action = /usr/share/samba/panic-action %d

####### Authentication #######

# Server role. Defines in which mode Samba will operate. Possible
# values are "standalone server", "member server", "classic primary
# domain controller", "classic backup domain controller", "active
# directory domain controller".
#
# Most people will want "standalone sever" or "member server".
# Running as "active directory domain controller" will require first
# running "samba-tool domain provision" to wipe databases and create a
# new domain.
   server role = standalone server

# If you are using encrypted passwords, Samba will need to know what
# password database type you are using.
   passdb backend = tdbsam

   obey pam restrictions = yes

# This boolean parameter controls whether Samba attempts to sync the Unix
 password with the SMB password when the encrypted SMB password in the
# passdb is changed.
   unix password sync = yes

# For Unix password sync to work on a Debian GNU/Linux system, the following
# parameters must be set (thanks to Ian Kahan <<kahan@informatik.tu-muenchen.de> for
# sending the correct chat script for the passwd program in Debian Sarge).
   passwd program = /usr/bin/passwd %u
   passwd chat = *Enter\snew\s*\spassword:* %n\n *Retype\snew\s*\spassword:* %n\n *password\supdated\ssuccessfully* .

# This boolean controls whether PAM will be used for password changes
# when requested by an SMB client instead of the program listed in
# 'passwd program'. The default is 'no'.
   pam password change = yes

# This option controls how unsuccessful authentication attempts are mapped
# to anonymous connections
   map to guest = bad user
   usershare allow guests = yes



[share]
   comment = share directory
   browseable = yes
   path = /media/hdd1/share
   read only = no
   available = yes
   guest ok = yes
   create mask = 0666
   directory mask = 0666

[printers]
   comment = All Printers
   browseable = no
   path = /var/spool/samba
   printable = yes
   guest ok = yes         ### この設定を間違えたせいで PDF が印刷できなかった
   read only = yes
   create mask = 0700

# Windows clients look for this share name as a source of downloadable
# printer drivers
[print$]
   comment = Printer Drivers
   path = /var/lib/samba/printers
   browseable = yes
   read only = yes
   guest ok = no
# Uncomment to allow remote administration of Windows print drivers.
# You may need to replace 'lpadmin' with the name of the group your
# admin users are members of.
# Please note that you also need to set appropriate Unix permissions
# to the drivers directory for these users to have write rights in it
   write list = root, @lpadmin
   admin users = @lpadmin

後は,サービスを再起動するか,システムを再起動すれば設定が反映される.

接続方法

Windows の場合は,「ネットワーク」にアクセスすることで,しばらくすると表示されるはずである.もし,表示されなければ,「コンピュータ」から「ネットワークドライブの割り当て」を選択し,「フォルダー」に「\\[Raspberry Pi の IP アドレス]\share」と入力する.ここでは,「\\192.168.33.12\share」とすれば良い.この時,「share」は,Samba の「comment = share directory」の 1 行上にある「share」を指す.名前を変えた場合は,注意すること.

Linux の場合は,場所バーに「smb://[Raspberry Pi の IP アドレス]/share」と入力すれば接続されるはずである.

次回

次回は,上にも記述してある「この設定を間違えたせいで PDF が印刷できなかった」という部分について説明しようと思う.