SAMBA: Share a folder in linux and access via Windows
Share a folder in Linux (CentOS, Debian) using samba (smb)
Solution:
The solution I'm using is with Samba. I'm using the username frank but please replace this with any username you wish. If you are using CentOS or Red Hat, replace "apt-get" by "yum" in the instructions below.
DEBIAN: sudo apt-get install samba CENTOS: sudo yum install samba FEDORA: sudo /usr/bin/dnf install samba
sudo nano /etc/samba/smb.conf
Uncomment this line in the global section to fix problem with file permission changing when editing with Windows:
;map archive = no
to
map archive = no
Add this at the end:
[www] comment = www path = /var/www valid users = @users force group = users create mask = 0770 directory mask = 0770 writable = yes
Save and close
$> sudo smbpasswd -a frank
$> sudo chgrp users /var/www
$> sudo usermod -a -G users frank (this adds the user frank to group users)
Also make sure that SE linux is permissive or disabled (see troubleshooting below) or that you enable some parameter if SE linux is kept enabled (this is the preferred solution).
$> sudo setsebool -P samba_enable_home_dirs on $> sudo chcon -Rt samba_share_t /your/shared/path/ # the -R is for recursive
On CentOS 7, you need to disable the firewall like this:
$> firewall-cmd --permanent --zone=public --add-service=samba $> firewall-cmd --reload
reboot
Mounting VFAT partitions for easy sharing within a group
Add gid=100, and change the permission umask 0007 (Warning! The permission numbers in fstab have a completely different numbering scheme than on shell !)
# # /etc/fstab # Created by anaconda on Tue Jan 27 22:34:57 2015 # # Accessible filesystems, by reference, are maintained under '/dev/disk' # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info # UUID=946c560f-5087-4c21-b3c7-48cf2875b07c / xfs defaults 1 1 UUID=28C2-AB46 /django vfat umask=0007,gid=100,shortname=winnt 0 0 UUID=88b09e0f-fab3-4a8c-b381-0416a28bf68e swap swap defaults 0 0 |
Troubleshooting:
You might want to check if samba service is running:
$> sudo service --status-all | grep smb
Usually it's called "smbd"
If it's not, confirm that samba is installed :
$> sudo apt-get install samba or
$> sudo yum install samba
And try to start the service
CentOS: $> sudo /sbin/service smb start
$> chkconfig smb on # to turn it on at reboot
Debian: $> sudo service samba start
Ubuntu: $> sudo service smbd start
Another problem could be the workgroup. Verify and edit the line workgroup = MYGROUP in /etc/samba/smb.conf, restart service
Another problem could be that SE linux is enabled. If you want to keep SE linux enabled, learn more at http://sharadchhetri.com/2013/02/17/how-to-install-and-configure-samba-server-in-centos-6/
To learn about SE linux status, type $> sestatus
If you want to set SE linux into permissive mode, type :
$> sudo gedit /etc/selinux/config
SELINUX=permissive
Another problem could be the firewall, to do a quick test, disable the firewall :
$> sudo service iptables save
$> sudo service iptables stop
$> sudo chkconfig iptables off
$> sudo service smb restart # or whatever command you use on your distribution to restart samba
Another problem is that you are running a virtual machine under a NAT. Use bridged mode instead. Also try pinging the machine IP address first.
Then finally another trick that did the job on a VM that was start / paused and kept running for months was simply to restart SMB. On this system the process were still running and displayed but had become unresponsive as if closed :
$> sudo service smb restart
For a public share
[public]
comment = Www
path = /var/www
guest ok = yes
public = yes
create mask = 0777
directory mask = 0777
writable = yes
For CentOS 7 the instructions are slightly different
systemctl enable smb.service systemctl enable nmb.service systemctl restart smb.service systemctl restart nmb.service If you keep the firewall open :
firewall-cmd --permanent --zone=public --add-service=samba firewall-cmd --reload If you leave SELINUX on, you need :
chcon -t samba_share_t my-shared-folder/
Recent Comments