0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【2025年04月版】Ubuntu24.04 で Samba で Windowsとファイル共有

Last updated at Posted at 2025-04-06

はじめに

Ubuntu側でファイル共有サーバを作りたいな。。。

そうだ、Samba しよう。

昔の記事は匿名アクセス設定だったので、今回はアクセス可能なユーザを限定する方向で。

匿名アクセスで構築する場合、Dockerで構築する場合は、以下の記事を参照してください。

前提条件

  • 環境
    Ubuntu24.04

  • 共有するフォルダ
    /export/smb_share

  • UbuntuのサーバのIPアドレス
    192.168.100.100

  • 共有を使うユーザ
    user1

インストール

$ sudo apt update
$ sudo apt install samba

設定

  • samba の設定ファイルを編集する
$ sudo vim /etc/samba/smb.conf
  :
  :
[global]
; [global] に追加
security = user
  :
  :
; 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 = ubuntu24.04 share
   path = /export/smb_share
   available = yes
   read only = no
   browsable = yes
   public = no
   writable = yes
   guest ok = no
   valid users = user1
  • samba の設定ファイルの編集内容をチェックする
$ testparm
  • 設定ファイルの修正にミスって、デフォルトに戻したいときは /usr/share/samba/smb.conf からコピーすれば良い
$ sudo cp /usr/share/samba/smb.conf /etc/samba/smb.conf
  • ユーザのsambaのパスワードを設定する
$ sudo smbpasswd -a user1
  • フォルダの権限を設定する
$ sudo chown user1:user1 /export/smb_share
$ sudo chmod 770 /export/smb_share
  • 必要であれば、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

Windows端末から、Explorerで、//192.168.100.100/smb_shared の共有を開く
ユーザとパスワードを求められるので、user1/入力したパスワードを入力する

macOS

macOS端末から、Finder -> 移動 -> サーバへ接続で、//192.168.100.100/smb_shared の共有を開く
ユーザとパスワードを求められるので、user1/入力したパスワードを入力する

Linux

  • smbclientで直接操作する場合
$ smbclient --user smbuser //192.168.100.100/share smbpassword
  • MOUNTする場合(/mnt/smbにマウント)
# mount -t cifs //192.168.100.100/share /mnt/smb -o user=smbuser

さいごに

かんたんでしたね

リンク

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?