Moving files in linux with samba

Well, we all know FTP, HTTP and other protocols would do the trick, but they are not the fastest way. because of setup and other considerations, especially when we are planing to use both windows and linux in the transactions, a low overhead method would be samba, or windows network file sharing

In windows, it is simple, we all know how to share a folder, and we all know how to open a shared folder over the network, in linux it is just as simple.

The detailed explanation of how to setup the samba server and share a folder is already in a post, but from the client side, you can copy a file by simply mounting the shared drive onto the linux server and copy or move files like you would a normal file or folder.

To mount we can simply execute the following

1- Install the client tools to mount the folder
apt-get install cifs-utils

then
mkdir /hds
mkdir /hds/smbmount

mount -t cifs //192.168.15.116/sharedfolder /hds/smbmount -o username=techg,noexec

That’s it, now use CP and MV as you would normally

One problem i faced with this method before was that my WD My Book Live shares would not mount, it threw an error

mount error(22): Invalid argument
Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)

The logs did not provide much help either

CIFS VFS: cifs_mount failed w/return code = -22

Turns out that the WD MyBook Live has an older version of Debian, and samba on that device had a max-v of 2, so the solution is to connect while specifying which version of samba works

mount -t cifs //192.168.2.116/sharedfolder /hds/smbmount -o vers=2.0,username=techg,noexec

The values for Version can be 2.0 2.1 3.0

Mounting samba shares at boot time

My NAS server is always online, I switch my PC off while I am asleep, yes, being green may be a factor I claim, but the truth is, my personal machine has spinning hard drives, and my backups are not always up to date, so if a disk fails while I am asleep, and ticks it’s way to its own demise, I would then remember that I should have been more green, Anyway, let us get to the mounting

1- create the file /home/qworqs/.smbcredentials and fill it up with the contents below

username=qworqs 
password=qwarks
domain=

Now that we have our credentials stored somewhere, we can add the following line to our fstab file, yes, it makes no sense that I have a folder called /hds that I mount all my disks and network shares to, but I have been doing this since I was young

So, open the file /etc/fstab and add the following line

//192.168.1.100/sharename /hds/100share cifs credentials=/home/qworqs/.smbcredentials,rw,uid=qworqs,gid=qworqs,noauto,nofail,x-systemd.automount,_netdev      0       0