Today I wanted to share some files between 2 of my Digital Ocean droplets and I thought it would be a fantastic time to look at making a Samba share on CentOS to make things easier.

So the first step is to actually install Samba which can be done by using:

yum install -y samba

Once Samba is installed you just need to edit the /etc/samba/smb.conf to add in the directory you want to share. I made a new user just for this one off set up which I will go over below.

First create a new user with a directory and set a password:

useradd -d /home/tmpshare -m tmpshare
passwd tmpshare

Now we need to edit the smb.conf using nano / vi or any other editor and add the information below to the bottom of the file:

nano /etc/samba/smb.conf

1
2
3
4
5
6
7
8
[tmpshare]
comment = temporary share
path = /home/tmpshare
public = no
valid users = tmpshare
writable = yes
browsable = yes
create mask = 0765

Once this has been done you need to restart the service with:

service smb restart

Now on the other server you can make a directory under /mnt and mount the share:

mkdir /mnt/share
mount -t cifs -o username=tmpshare //ip-or-hostname/tmpshare /mnt/share

If you have selinux enabled there are some extra steps needed, You can see if it is enabled by running sestatus.

chcon -R -t samba_share_t /home/tmpshare/
semanage fcontext -a -t samba_share_t /home/tmpshare/
setsebool -P samba_enable_home_dirs on

Another issue you could run into is the password not being accepted, There is a simple fix for this as well.

smbpasswd -a tmpshare