1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

RaspberryPi3, CentOS7, Sambaによる自宅ファイルサーバ構築記録

Last updated at Posted at 2021-02-01

概要

ラズパイで自宅用ファイルサーバを構築したときの手順を記録しておきます。
様々なサイトや書籍を参照しましたが私の環境では下記で正常動作しております。

1. OSインストール

ラズパイ用のインストールイメージをダウンロードします。
ファイル名 : CentOS-Userland-7-armv7hl-Minimal-1603-RaspberryPi3.img
ダウンロード元: http://ftp.jaist.ac.jp/pub/Linux/CentOS-vault/altarch/7.2.1511/isos/armhfp/

MicroSDへの書き込みはWin32 Disk Imager にて実施しました。
image.png

2. Sambaインストール

rootでログインしSambaをインストールします。

[root@centos-rpi3 ~]# yum install samba samba-client samba-winbind samba-winbind-clients
(中略)
Complete!
[root@centos-rpi3 ~]

3.fiwalld設定

firewalldが動作していることを確認します。

[root@centos-rpi3 ~]# firewall-cmd --state
running
[root@centos-rpi3 ~]#

この場合、Sambaへのアクセスを許可します。

[root@centos-rpi3 ~]# firewall-cmd --add-service=samba --zone=public --permanent
success
[root@centos-rpi3 ~]# firewall-cmd --add-service=samba-client --zone=public --permanent
success
[root@centos-rpi3 ~]#

4. SELinuxの設定

初期状態で下記となっているSELinuxの設定を変更します。

[root@centos-rpi3 ~]# getsebool -a | grep samba
samba_create_home_dirs --> off ★ホームディレクトリの作成を許可
samba_domain_controller --> off ★Sambaユーザのホームディレクトリを共有先として許可
samba_enable_home_dirs --> off ★NTドメコンを許可
samba_export_all_ro --> off
samba_export_all_rw --> off ★共有先フォルダの読み書きを許可
samba_load_libgfapi --> off
samba_portmapper --> off
samba_run_unconfined --> off
samba_share_fusefs --> off ★FUSEFSのエクスポートを許可
samba_share_nfs --> off
sanlock_use_samba --> off
tmpreaper_use_samba --> off ★Sambaがtmpwatchを許可
use_samba_home_dirs --> off ★Sambaのホームディレクトリの使用を許可
virt_sandbox_use_samba --> off
virt_use_samba --> off
[root@centos-rpi3 ~]#

上記★部分の設定をONにします。

[root@centos-rpi3 ~]#
[root@centos-rpi3 ~]# setsebool -P samba_create_home_dirs on
[root@centos-rpi3 ~]# setsebool -P samba_domain_controller on
[root@centos-rpi3 ~]# setsebool -P samba_enable_home_dirs on
[root@centos-rpi3 ~]# setsebool -P samba_export_all_rw on
[root@centos-rpi3 ~]# setsebool -P samba_share_fusefs on
[root@centos-rpi3 ~]# setsebool -P samba_share_nfs on
[root@centos-rpi3 ~]# setsebool -P tmpreaper_use_samba on
[root@centos-rpi3 ~]# setsebool -P use_samba_home_dirs on
[root@centos-rpi3 ~]#

変更が反映されていることを確認します。

[root@centos-rpi3 ~]# getsebool -a | grep samba
samba_create_home_dirs --> on
samba_domain_controller --> on
samba_enable_home_dirs --> on
samba_export_all_ro --> off
samba_export_all_rw --> on
samba_load_libgfapi --> off
samba_portmapper --> off
samba_run_unconfined --> off
samba_share_fusefs --> on
samba_share_nfs --> on
sanlock_use_samba --> off
tmpreaper_use_samba --> on
use_samba_home_dirs --> on
virt_sandbox_use_samba --> off
virt_use_samba --> off
[root@centos-rpi3 ~]#

6. ワークグループの設定

★部分をデフォルト(SAMBA)からWORKGROUPに変更します。

[root@centos-rpi3 ~]# vi /etc/samba/smb.conf

[global]
        workgroup = WORKGROUP ★
        security = user
        passdb backend = tdbsam
        printing = cups
        printcap name = cups
        load printers = yes
        cups options = raw
(以下省略)

設定後、Sambaを再起動します。

[root@centos-rpi3 ~]# systemctl start smb.service
[root@centos-rpi3 ~]# systemctl start nmb.service
[root@centos-rpi3 ~]# systemctl start winbind.service

7. Sambaアカウントを作成

各クライアントからのログイン用ユーザをOS別に作成しパスワードを設定します。
Windows 10

[root@centos-rpi3 ~]# useradd winguest
[root@centos-rpi3 ~]# passwd winguest

Mac OS.X

[root@centos-rpi3 ~]# useradd macguest
[root@centos-rpi3 ~]# passwd macguest

Ubuntu Desktop 20.10

[root@centos-rpi3 ~]# useradd linuxguest
[root@centos-rpi3 ~]# passwd linuxguest

ホームディレクトリが作成されていることを確認します。

[root@centos-rpi3 ~]# ls /home
linuxguest  macguest  me  winguest
[root@centos-rpi3 ~]#

作成したSambaアカウントはpdbeditコマンドにて設定します。
(ここからサーバ名が変わってますが、/etc/hostnameファイルを更新しました)

[root@SambaServer ~]#
[root@SambaServer ~]# pdbedit -L ★Sambaアカウントの一覧を表示。作成前は何も出ない。
[root@SambaServer ~]#

[root@SambaServer ~]# pdbedit -a winguest ★-aオプションでユーザを追加。
new password: ★パスワードを入力。
retype new password: ★パスワードを入力。
Unix username:        winguest
NT username:
Account Flags:        [U          ]
User SID:             S-1-5-21-1856806690-3704889449-4102419222-1000
Primary Group SID:    S-1-5-21-1856806690-3704889449-4102419222-513
Full Name:
Home Directory:       \\sambaserver\winguest
HomeDir Drive:
Logon Script:
Profile Path:         \\sambaserver\winguest\profile
Domain:               SAMBASERVER
Account desc:
Workstations:
Munged dial:
Logon time:           0
Logoff time:          never
Kickoff time:         never
Password last set:    Thu, 28 Jan 2021 17:24:37 UTC
Password can change:  Thu, 28 Jan 2021 17:24:37 UTC
Password must change: never
Last bad password   : 0
Bad password count  : 0
Logon hours         : FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
[root@SambaServer ~]#

Mac用、Linux用アカウントも同様に設定します。

8. Windows 10から接続

エクスプローラにIPアドレスを入力し、認証情報を入力すると、作成したホームディレクトリが表示されます。
image.png

9. Mac OS Xから接続

Finder上で同様に認証情報を入力すると共有フォルダに接続できます。
image.png

10. Ubuntu Desktop 20.10から接続

ファイルマネージャ上でOther Locationsから接続先を入力しConnectをクリックします。
image.png

認証情報を入力するとホームディレクトリへアクセスできます。
image.png

書き洩らしが見つかったら随時追記していきます。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?