ホーム DoRuby Samba 設定メモ

Samba 設定メモ

この記事はアピリッツの技術ブログ「DoRuby」から移行した記事です。情報が古い可能性がありますのでご注意ください。

VirtualBox 上で CentOS や Ubuntu を起動させ、 Samba でファイル共有

Centos6の場合

sudo yum install -y samba
sudo chmod 755 /home/$USER
sudo smbpasswd -a $USER
sudo cp -a /etc/samba/smb.conf /etc/samba/smb.conf.org
sudo vi /etc/samba/smb.conf # 編集方法は以下参照
sudo /etc/rc.d/init.d/smb start
sudo /etc/rc.d/init.d/nmb start
sudo chkconfig smb on
sudo chkconfig nmb on
sudo setsebool -P samba_export_all_rw 1
sudo /etc/rc.d/init.d/iptables stop
sudo chkconfig iptables off
sudo chkconfig ip6tables off

編集方法

  • 57行目の下に追加
     58 ### START ###
     59         unix charset = UTF-8
     60         dos charset = CP932
     61         display charset = UTF-8
     62 ### END ###
  • 79行目を変更
     79 ### START ###
     80 #       workgroup = MYGROUP
     81         workgroup = WORKGROUP
     82 ### END ###
  • 88行目の下に追加
     89 ### START ###
     90         hosts allow = 127.0.0.1 10. 172.16. 192.168.
     91 ### END ###
  • 232行目を変更
    232 ### START ###
    233 #       load printers = yes
    234         load printers = no
    235         disable spoolss = yes
    236 ### END ###
  • 266行目の下に追加
    267 ### START ###
    268         create mask = 644
    269         directory mask = 755
    270 ### END ###

CentOS7 の場合

sudo yum install -y samba
sudo chmod 755 /home/$USER
sudo smbpasswd -a $USER
sudo cp -a /etc/samba/smb.conf /etc/samba/smb.conf.org
sudo cp /etc/samba/smb.conf.example /etc/samba/smb.conf
sudo vi /etc/samba/smb.conf       # 編集方法は以下参照
sudo systemctl enable smb.service
sudo systemctl enable nmb.service
sudo systemctl restart smb.service
sudo systemctl restart nmb.service
sudo setsebool -P samba_export_all_rw 1
sudo systemctl stop firewalld

編集方法

差分が以下のようになるよう修正する

[admin@localhost ~]$ diff -uprN /etc/samba/smb.conf.example /etc/samba/smb.conf
--- /etc/samba/smb.conf.example 2017-11-28 01:21:52.000000000 +0900
+++ /etc/samba/smb.conf 2018-05-02 20:50:00.157765018 +0900
@@ -60,6 +60,9 @@
 #======================= Global Settings =====================================

 [global]
+unix charset = UTF-8
+dos charset = CP932
+display charset = UTF-8

 # ----------------------- Network-Related Options -------------------------
 #
@@ -81,13 +84,13 @@
 # hosts deny = the hosts not allowed to connect. This option can also be used on
 # a per-share basis.
 #
-       workgroup = MYGROUP
+       workgroup = WORKGROUP
        server string = Samba Server Version %v

 ;      netbios name = MYSERVER

 ;      interfaces = lo eth0 192.168.12.2/24 192.168.13.2/24
-;      hosts allow = 127. 192.168.12. 192.168.13.
+       hosts allow = 127.0.0.1 10. 172.16. 192.168.

 # --------------------------- Logging Options -----------------------------
 #
@@ -244,7 +247,8 @@
 # printcap name = used to specify an alternative printcap file.
 #

-       load printers = yes
+       load printers = no
+       disable spoolss = yes
        cups options = raw

 ;      printcap name = /etc/printcap
@@ -278,6 +282,8 @@
        writable = yes
 ;      valid users = %S
 ;      valid users = MYDOMAIN\%S
+       create mask = 644
+       directory mask = 755

 [printers]
        comment = All Printers

Ubuntu の場合

sudo apt-get install -y samba
sudo pdbedit -a $USER
sudo cp -a /etc/samba/smb.conf /etc/samba/smb.conf.org
sudo vi /etc/samba/smb.conf        # 以下参照
sudo systemctl restart smbd
sudo systemctl restart nmbd

編集方法

差分が以下のようになるよう修正する

$ diff -uprN /etc/samba/smb.conf.org /etc/samba/smb.conf
--- /etc/samba/smb.conf.org     2018-05-02 18:16:25.567600455 +0900
+++ /etc/samba/smb.conf 2018-05-02 18:20:40.762445925 +0900
@@ -190,13 +190,13 @@
 # Un-comment the following (and tweak the other settings below to suit)
 # to enable the default home directory shares. This will share each
 # user's home directory as \\server\username
-;[homes]
-;   comment = Home Directories
-;   browseable = no
+[homes]
+   comment = Home Directories
+   browseable = no

 # By default, the home directories are exported read-only. Change the
 # next parameter to 'no' if you want to be able to write to them.
-;   read only = yes
+   read only = no

 # File creation mask is set to 0700 for security reasons. If you want to
 # create files with group=rw permissions, set next parameter to 0775.
@@ -211,7 +211,7 @@
 # Un-comment the following parameter to make sure that only "username"
 # can connect to \\server\username
 # This might need tweaking when using external authentication schemes
-;   valid users = %S
+   valid users = %S

 # Un-comment the following and create the netlogon directory for Domain Logons
 # (you need to configure Samba to act as a domain controller too.)

ファイアウォールのポート開放

sudo ufw allow 137
sudo ufw allow 138
sudo ufw allow 139
sudo ufw allow 445

すべてのポートを空ける場合は以下

sudo ufw default ALLOW

Ubuntuからアクセスする方法(Ubuntuがクライアントの場合)

sudo apt-get install -y cifs-utils
sudo mkdir /mnt/XXX

※「XXX」は任意

マウント

sudo mount.cifs //AAA.AAA.AAA.AAA/BBB /mnt/XXX/ -o username=BBB,uid=$(id -u),gid=$(id -g)

AAA : サーバIP
BBB : サーバ側のユーザ名

アンマウント

sudo umount /mnt/XXX
記事を共有

最近人気な記事