はじめに
Ubuntu側でファイル共有サーバを作りたいな。。。
そうだ、Samba しよう
前提条件
- 環境
$ uname -a
Linux smb_host 5.15.0-75-generic #82-Ubuntu SMP Tue Jun 6 23:10:23 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
$ cat /etc/os-release
PRETTY_NAME="Ubuntu 22.04.2 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.2 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
-
共有するフォルダ
/export/smb_share
-
UbuntuのサーバのIPアドレスは、
192.168.100.100
インストール
$ sudo apt update
$ sudo apt install samba
$ samba --version
Version 4.15.13-Ubuntu
設定
- samba の設定ファイルを編集する
$ sudo vim /etc/samba/smb.conf
:
:
; printers セクションをコメントアウト
;[printers]
; comment = All Printers
; browseable = no
; path = /var/spool/samba
; printable = yes
; guest ok = no
; read only = yes
; create mask = 0700
:
:
; print$ セクションをコメントアウト
;[print$]
; comment = Printer Drivers
; path = /var/lib/samba/printers
; browseable = yes
; read only = yes
; guest ok = no
:
:
[shared]
comment = ubuntu22.04 share
path = /export/smb_share
available = yes
read only = no
browsable = yes
public = yes
writable = yes
guest ok = yes
- samba の設定ファイルの編集内容をチェックする
$ testparm
- 設定ファイルの修正にミスって、デフォルトに戻したいときは
/usr/share/samba/smb.conf
からコピーすれば良い
$ sudo cp /usr/share/samba/smb.conf /etc/samba/smb.conf
- フォルダの権限を設定する
$ sudo chmod 777 /export/smb_share
$ ls -alt /export/smb_share
total 16
drwxr-xr-x 1 root root 0 Jun 22 14:29 .
drwxr-xr-x 1 root root 18 Jun 21 19:47 ..
- 必要であれば、ufw の 139 と 445 を開ける
$ sudo ufw allow 139/tcp
$ sudo ufw allow 445/tcp
サービスの再起動
$ sudo systemctl restart smbd
サービスの自動起動の設定
$ sudo systemctl enable smbd
$ sudo systemctl enable nmbd
動作確認
Windows端末から、//192.168.100.100/shared
で共有を開く
さいごに
かんたんでしたね