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?

Ubuntuでsambaサーバー立てるときはポート開放しよう

Last updated at Posted at 2025-04-20

ローカルネットワークまたは VPN 経由で mac (OS Sequoia) から Ubuntu 20.04 ホストに SMB 接続したいときのトラブルシューティング経験談です。


環境

  • OS: Ubuntu 20.04 LTS
  • クライアント: macOS Sequoia
  • 接続方法: ローカルネットワークまたは VPN

手順とトラブルシューティング

  1. Samba のインストール

    sudo apt update
    sudo apt install -y samba
    
  2. 設定ファイルのバックアップと編集

    cd /etc/samba/
    sudo cp -a smb.conf smb.conf.backup
    sudo nano smb.conf
    

    以下を追記:

    [global]
        client min protocol = NT1
        server min protocol = NT1
    
    [ユーザー名]
        path = /home/ユーザー名/Data   # マウントしたいディレクトリ
        browsable = yes
        writable   = yes
        guest ok   = no
        read only  = no
    
  3. Samba ユーザーの追加

    sudo smbpasswd -a [ユーザー名]
    # プロンプトに従いパスワードを設定
    
  4. サービスの再起動

    sudo systemctl restart smbd
    
  5. 接続確認(ローカルホスト)

    sudo apt install -y smbclient
    smbclient -L localhost -U%
    

    出力:

    Sharename       Type      Comment
    ---------       ----      -------
    print$          Disk      Printer Drivers
    ユーザー名        Disk      
    IPC$            IPC       IPC Service (ホスト名 server (Samba, Ubuntu))
    
    Reconnecting with SMB1 for workgroup listing.
    
    Server         Comment
    ---------      -------
    Workgroup      Master
    

    ※ まだクライアントからは見えない...。

  6. ファイアウォールの設定

    • Samba アプリケーションプロファイルを確認

      sudo ufw app list
      
    • 特定ネットワークからのポート 445(TCP)を許可

      sudo ufw allow from 192.168.XX.0/24 to any port 445 proto tcp
      sudo ufw reload
      
  7. mac の Finder から接続

    • Finder メニューの「移動」→「サーバーに接続...」

    • サーバーアドレスに以下を入力

      smb://<Ubuntu サーバーの IP アドレス>
      
    • ユーザー名・パスワードを入力して接続成功


ここが効いたのか?

  • プロトコル設定: client min protocol / server min protocolNT1 に。
  • ユーザー追加: smbpasswd -a で Samba 用ユーザーを作成。
  • ファイアウォール: UFW で TCP 445 ポートを許可。
  • 接続確認: smbclient -L localhost -U% で共有状況をチェック。

以上で、mac から Ubuntu 20.04 上の Samba 共有フォルダにアクセスできるようになりました。ufwで445ポートを指定して開放しないと接続できませんでした。Dockerコンテナがいっぱい立ち上がってるので再起動したくなかったのですが、再起動していれば手動でufwで445ポートを開放しなくても接続できたのでしょうか...?

参考文献

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?