1. Approach
This docu documents install and usage of Samba.
Why yet another docu as all existings?
I have had problems with Samba also in the beginning of the 2000th. And it seems it is not better yet. The most manuals explain only how to do, but not why and what’s happen.
2. Access from Windows to Linux
This requires a running samba service on the linux PC with a proper configuation.
2.1. Install Samba
On debian
sudo apt-get install samba
sudo apt-get install cifs-utils
The second line is for access Access from Linux to Windows
After change in the smb.conf:
sudo systemctl restart smbd.service
2.2. Samba config etc/
/etc/samba/smb.conf
Contains the configuration for the samba service.
It is read on system start and reread if sudo service smbd restart is called.
For a share append the following entry on end:
[data] path = /mnt/data force user = hartmut public = yes writable = yes comment = smb share printable = no guest ok = yes read only = no create mask = 0777 directory mask = 777 [hartmut] path = /home/hartmut force user = hartmut public = yes writable = yes comment = smb share printable = no guest ok = yes read only = no create mask = 0777 directory mask = 777
-
[data]and[hartmut]are the name of the net use connection = share, used in Windows innet use, -
path = /path/tothe path which is accessed with the share. The first path goes to the 'Data' directory, which is here an independent partition on hard disk mounted in the shown directory/mnt/data. The second entry is the path the home directory of me.Note that it is recommended to hold independent data on an extra partition and not in the home directory. This helps on changing the operation system (Linux distribution etc).
-
force user = hartmutis the user name which is used for access to the files onpath =. It means the/mnt/data/should be accessible byhartmutas user on Linux. Set it withchusrandchgrpon creation or justchmod. -
The rest may be obvious, it’s copied from some examples.
To edit smb.cnf you can use
sudo nano /etc/samba/smb.conf
nano is a simple text editor (better and newer than vi in my mind) but even with sophisticated but possible handling.
It runs as console application, hence can edit immeditately root files with sudo.
Important hint: Paste content from clipboard is not intrinsically supported from nano,
but because it’s an console application,
you can use <ctrl-sh-V> as usual for konsole or other console applications to paste.
It is received and executed by the console app and then interpret as key strokes for nano.
2.3. check whether Samba is installed, check the status, restart Samba
sudo smbstatus
This shows an overview of currently connected accesses (from Windows or other Linux).
systemctl status smbd systemctl status smbd.service
Both effects the same and shows the status of any service,
here from the smbd service which is Samba.
sudo systemctl restart smbd
This command is necessary to restart samba after the smb.conf was changed.
2.4. Network connection net use…
Now it is possible to make a network connection in Windows as usual between Windows PC. The batch script or command line version is:
set IP=192.168.2.70 ping %IP% if exist R:\ subst E: /D if exist R:\ net use R: /delete net use R: \\%IP%\data /PERSISTENT:NO /USER:hartmut
-
IP is set as environment variable which is here
192.168.2.70as the IP from the Linux PC. -
ping the destination to see whether it is reachable in network, to see the situation is ok.
-
It may be possible that R: is mounted in Windows, with a
substor a network drive before, remove thesubstor net use before. -
On
net use: Thedatais the share name. -
Whether
/USER:hartmutis used - not tested yet. It should be sufficient to determine the user on the Linux side. It is sufficient for Windows network connections. For the Linux side the entryforce user = hartmutin thesmb.confis relevant.
3. Access from Linux to Windows
This requires additional to samba the cifs-utils.
The older service smbfs is no more actually.
sudo apt-get install cifs-utils
After them any available network drive on Windows can be mounted. For that I use the following shell script, example which is executed on demand if necessary:
Script /batch/start/mnt-1-69-Q-T.sh:
ip a IP="192.168.2.69" ping $IP if ! test -d /mnt/Qd; then sudo mkdir /mnt/Qd sudo chown hartmut /mnt/Qd sudo chgrp hartmut /mnt/Qd sudo mkdir /mnt/Qd/Qdata sudo mkdir /mnt/Qd/ramdisk fi echo umount /mnt/Qd/Qdata echo umount /mnt/Qd/ramdisk sudo umount /mnt/Qd/Qdata sudo umount /mnt/Qd/ramdisk ls /mnt read -p "is unmounted ... press any Key" INPUT ##https://unix.stackexchange.com/questions/68079/mount-cifs-network-drive-write-permissions-and-chown echo mount -t cifs -o user=hartmut,uid=$(id -u),gid=$(id -g) //$IP/tmp /mnt/Qd/ramdisk sudo mount -t cifs -o user=hartmut,uid=$(id -u),gid=$(id -g) //$IP/tmp /mnt/Qd/ramdisk ls /mnt/Qd/ramdisk read -p "Tdata ... press any Key" INPUT echo mount -t cifs -o user=hartmut,uid=$(id -u),gid=$(id -g) //$IP/D /mnt/Qd/Qdata sudo mount -t cifs -o user=hartmut,uid=$(id -u),gid=$(id -g) //$IP/D /mnt/Qd/Qdata ls /mnt/Qd/Qdata read -p "Qdata ... press any Key" INPUT
-
Sets and uses the IP-address via the
$IPvariable. -
This script creates, if not exists, the necessary folders in the
/mntdirectory. -
Then it umount given
-
The
Dandtmpafter the ip//$IP/is the network name in Windows for the network drive (maybe a longer name, but for me it is the subst drive D:). -
/mnt/Qd/datais the directory name on linux where the file tree is shown. -
Interisting feature: Om my Windows PC the TMP directory is completely located in a RAM disk. The content of the RAM disk is not stored. All temporaries of Windows are not preserved. This runs. This TMP directory (on Windows on drive T:, e.g.) is mounted in network to allow storing data to exchange only on the RAM drive, saving access for the SSD (or also HDD).
Why use a second directory use /mnt/Qd/data instead /mnt/Qdata
That is experience:
The directory Qdata below mnt/Qd is used
because the mounted drive on the other side (Windows) may have problems,
e.g. computer is switched off after mounting, cable unplugged of an possible SSD via USB.
Then the access to /mnt itself wold be wait till timeouts if the mount point is immediately below /mnt,
The other mounted ressources cannot even be accessed, till the problem is detected and/or fixed.
With the sub directory below mnt/Qd/… This access problems occurs only for /mnt/Qd
and not already by the access to /mnt.
4. Unmount network drives
If an USB drive is disconnected, usual it is detected while unplug.
But a network drive can be available on mount, but later in the mounted state not available. Because for example the cable is unplugged or the computer is off. This is often after standby without unmount, then recover, but the other PC is not available.
sudo umount /home/Qd/data sudo umount /home/Wd/ramdisk
started per command line, maybe also after login after wakeup from standby unmounts, and the mounting can be done with the call of the mount scripts again, see above.