Samba
File sharing, copying and sync
- Map Network drive
- Mount drives
- Samba Share Setup
- Samba Users
- Troubleshooting Samba / Cifs share Permissions
Map Network drive
First, Need to make sure you have Samba and smbclient and, Cifs-utils. Install them.
create a mount point (if you haven't already)
sudo mkdir /directr/to/moun/to
Mount the volume
sudo mount -t cifs //[addressofshare]/[folderofshare] -o usernam=ofshare /[localdirectorytomountto]
Exaple:
sudo mount -t cifs //192.168.3.456/smbshare -o username=bob /mnt/remote
Then, when asked for password, type in password of the share folder that is hosting the share you are trying to access, not your local machine.
Make it permanent by going into the fstab
vim /etc/fstab
Line 2 is what you need to enter it (change it to your own of course).
# <file system> <mount point> <type> <options> <dump> <pass>
//192.168.3.456/smbshare /mnt/remote cifs username=bob,passowrd=eatit 0 0
Test to see if it mount worked
umount /storage/location
mount -a
Troubleshooing
Mount drives
If disk is already formatted, You can mount it. You may need to create a file system for it though.
If you do, Replace XY
accordingly, but double check that you are specifying the correct partition
mkfs.ext4 /dev/sdXY
Do that to all the drives/partitions you need to.
Now you should be able to go to "Disk manager" in the GUI or, mount the drive/s manually.
Terminal:
create a mount point (if you haven't already)
sudo mkdir /directr/to/moun/to
Now mount it:
mount /dev/sbxy /new/mounted/location
Mounting from fstab
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point> <type> <options> <dump> <pass>
# /this uses the UUID of the drive and mounts it do the directory you want it to go to
UUID=574c96bf-f2cb-49b8-9196-232a24047f94 /mount/dir ext4 errors=remount-ro 0 0
# /this uses the drive location and mounts it to the directory
/dev/sdb /mount/dir ext4 errors=remount-ro 0 0
Samba Share Setup
Make sure you have a directory set up that you are going to be sharing. If it is going to be a new one, create that directory where you need it, on the local machine that the data will live. /home/the/share/file/location or something like that.
If it already exists, just keep that in mind for when its needed in the config file.
Now, make that directory, unless you already have one in mind.
mkdir /home/the/share/file/location
Go to the config file:
I'm using "vim". Use whatever you want.
sudo vim /etc/samba/smb.conf
Inside the config file, add the following:
[sambashare_file_name]
comment = Samba on Ubuntu
path = /home/the/share/file/location
read only = no
browsable = yes
Restart Samba:
sudo service smbd restart
or
sudo systemctl restart smbd
You prob have a firewall so, fix those settings now.
For UFW:
sudo ufw allow samaba
Samba Users
Since Samba doesn't use the system account password, we need to set up a Samba password for our user account
sudo smbpasswd -a username
Note:
The user name must belong to a system account or else it won't work.
The password is the part that will change to its own Samba password.
Troubleshooting Samba / Cifs share Permissions
Cifs share doesn't preserve permission configuration in smb.conf (755 instead of 777)
There are two options that can help 'save the day': dir_mode and file_mode. (placeholders in green italics)
Setting both these to 0777 gives full permissions that the host smb server allows for the user in question.
sudo mount -t cifs -o rw,username=yourusername,dir_mode=0777,file_mode=0777 //share/directory ~/mnt/local/directory
Or if it s in your fstab file:
//192.168.1.234/Sharename /mnt/local/directory cifs username=yourusername,dir_mode=0777,file_mode=0777,password=yourpassword 0 0