LoginSignup
14
8

More than 3 years have passed since last update.

VMware上のCentOSにSambaを用いてMacとの共有フォルダを作る

Last updated at Posted at 2016-09-04

概要

実行環境はLinuxで、コーディングは使い慣れたMac上のエディタで行いたい。

そこで、VMware Fusion上のCentOSにSambaで共有フォルダを作り
Mac上でファイルの編集できるようする。

環境

Mac OS X 10.11.6
CentOS 7.2.1511

sambaのインストール

sudo yum install samba
# 自動起動
systemctl enable smb
# sudo chkconfig smb on # CentOS6以前

共有ディレクトリを作成

mkdir /home/samba
sudo chmod -R 0777 /home/samba/
sudo chown -R nobody:nobody /home/samba

SELinuxの設定しないと上記で権限を変更しても、読み書きができない

# SELinuxの設定
sudo chcon -t samba_share_t /home/samba/ # 特定ディレクトリへのアクセスを許可
# あるいは
# setsebool -P samba_enable_home_dirs on # home以下へのアクセスを許可

sambaの初期設定

# smb.confをバックアップ
sudo cp -ap /etc/samba/smb.conf /etc/samba/smb.conf.bk
# smb.confを編集
sudo vi /etc/samba/smb.conf
smb.conf
; ===== 以下を追記 =====
[samba]
        comment = samba directory
        path = /home/samba
        public = yes
        browseable = yes
        writable = yes
        hosts allow = 127. 192.168. # 内部からのアクセスのみ許可
# smb.confの記述ミスをチェック
testparm

ユーザーの追加

# 既存ユーザ「user-name」を追加
sudo pdbedit -a user-name
# sambaを再起動
systemctl restart smb
# /etc/init.d/smb restart # CentOS6以前

パケットフィルタリングの設定

CentOS7からはiptablesからfirewalldへと移行したらしい。
どちらかを使う。

1. firewalldの場合(CentOS7)

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

2. iptablesの場合

# firewalldを無効に
systemctl stop firewalld # CentOS7
systemctl disable firewalld # CentOS7
# iptablesのインストール
sudo yum install iptables-services
# iptableを編集、あるいは作成
sudo vi /etc/sysconfig/iptables

iptablesの内容はここに書かれているものをそのまま使いました。

# 自動起動
systemctl enable iptables
systemctl start iptables
# sudo /etc/init.d/iptables restart # CentOS6以前

Mac側から接続

Finder→「サーバへ接続」からマウントできれば成功

参考

14
8
1

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
14
8