LoginSignup
9
9

More than 5 years have passed since last update.

CentOS7.4にsambaサーバを構築しました ※python開発環境用

Posted at

はじめに

このドキュメントは自宅にsambaサーバを構築した際のメモになります。
pythonの開発環境を作成するためにsambaを導入しました。
samba上にpythonのソースを配置することで、sambaの共有先をwindowsでマウントしてエディタ(atomなど)でソースコードを書けるようになります。

今後、sambaサーバを構築する方の参考になれば幸いです。

sambaインストール、初期設定

インストール

yum install -y samba samba-client samba-common

初期設定

設定ファイル(smb.conf) ※ユーザ名、グループはxxxxxxxxxxにしています。

# See smb.conf.example for a more detailed config file or
# read the smb.conf manpage.
# Run 'testparm' to verify the config is correct after
# you modified it.

[global]
    # Linux側の日本語コードの指定。SJIS/EUC/CAP/HEXから指定する
    # smb.conf自体の文字コードをこの項目で指定した文字コードに合わせます
    unix charset = UTF-8

    # クライアントが使用する言語を指定します
    # 「932」は日本語を表します
    dos charset = CP932

    # ワークグループを設定します
    workgroup = WORKGROUP

    # Sambaサーバに付加するコメント
    server string = Samba Server %v

    # 暗号化パスワードを使用するか
    encrypt passwords = Yes

    # guest ユーザーにアクセスを許可するかどうか設定します
    # Bad User:ゲストユーザーとしてのアクセスを許可します
    # Never:ゲストユーザーのアクセスを拒否します
    map to guest = Bad User

    # 通信ソケットのオプション
    socket options = TCP_NODELAY SO_RCVBUF=8192 SO_SNDBUF=8192

    # WINSサーバの代理サーバとしてDNSを使うか
    dns proxy = no

    # ブラウジング機能の設定です
    # 必要な場合以外はデフォルト値で運用が推奨されています
    os level = 1

    # クライアントの認証方法にuser認証を利用する
    security = user

    # Linux システムのパスワードとSambaのパスワードを同期させる
    unix password sync = yes

    # Sambaが通信を許可するホスト、ネットワークIPアドレス、ネットワークインターフェースなどを指定します
    # 下記の場合、eth0に割り当てられているIPアドレスと、
    # 自ホストと、192.168.11.*のIPアドレスを持つIPアドレスからSmabaへの接続が許可される
    #interfaces = eth0 127.0.0.1 192.168.0.0/24

    # Sambaに関係するネーム・サービスへの接続を、上記interfaces項目に指定したホストだけに限定するかどうか
    # (yes:限定する)
    #bind interfaces only = yes

    # Sambaへの接続を許可するホストやネットワークを指定します
    # 下記の場合、192.168.0.*のIPアドレスを持つホストからの接続のみ許可します
    #hosts allow = 192.168.0.

    # NETBIOS名
    netbios name = Dev

    # プリンターを共有しない
    load printers = no
    disable spoolss = yes

[document]
    # Windows側から見た時に付加されるコメント
    comment = Document root.

    # 共有するディレクトリのパス
    path = /labo/

    # guestユーザのアクセスを許可するか
    guest ok = no

    # 読み出しのみ可能か
    read only = no

    # 書き込みを許可する
    writable = Yes

    # どのグループでアクセスさせるか
    force group = xxxxxxxxxx

    # 強制的にファイルに与えるアクセス権
    force create mode = 0664

    # 強制的にディレクトリに与えるアクセス権
    force directory mode = 0775

    # 特定のユーザのみにアクセスを許可する場合には、
    # valid users項目に「,」区切りでユーザ名を記述してゆく
    # 特定のグループのみにアクセスを許可する場合には、
    # valid users項目にグループ名の最初に「@」を付加したグループ名を記述する
    # Linuxのグループ名「family」のみ接続を許可する
    valid users = xxxxxxxxxx

[homes]
    # Windows側から見た時に付加されるコメント
    comment = %U's Home directory

    # パス
    path = %H/

    # Windowsの共有一覧にホームディレクトリを表示するか
    browseable = No

    # 読み出しのみ可能か
    read only = No

    # 書き込みを許可する
    writable = Yes

    # ファイルにはこのアクセス権(644)が付与される
    create mode = 0644

    # ディレクトリにはこのアクセス権(775)が付与される
    directory mode = 0775

    vfs objects = recycle
    recycle:repository = .recycle
    recycle:keeptree = no
    recycle:versions = yes
    recycle:touch = no
    recycle:maxsize = 0
    recycle:exclude = *.tmp ~$*

[printers]
    comment = All Printers
    path = /var/tmp
    printable = Yes
    create mask = 0600
    browseable = No

[print$]
    comment = Printer Drivers
    path = /var/lib/samba/drivers
    write list = root
    create mask = 0664
    directory mask = 0775

ユーザ追加 ※xxxxxxxxxxはユーザ名

smbpasswd -a xxxxxxxxxx

samba起動

systemctl enable smb.service
systemctl enable nmb.service
systemctl restart smb.service
systemctl restart nmb.service

firewall設定

firewall-cmd --permanent --zone=public --add-service=samba
firewall-cmd --reload

その他

各種ディレクトリ

# 設定ファイル
/etc/samba/smb.conf

# 共有先ディレクトリ
/labo/

Windowsから接続時にアクセス拒否された場合の対応・・・

下記のコマンドを実行してlinuxシステムにユーザを登録してください。

pdbedit -L
pdbedit -a -u xxxxxxxxxx

こちらのサイトを参考に作業をしました。
管理者/smbd の設定

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