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
TODO
Is it entered to run on next system start after installation already?
sudo systemctl restart smbd.service
2.2. Samba config etc/
/etc/samba/smb.conf
Contains the configuration for the smbd service.
It is read on system start and reread if sudo service smbd restart is called.
For a share it contains the entry:
[hartmut] path = /home/D 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-E] path = /home/E/d force user = hartmut public = yes writable = yes comment = smb share printable = no guest ok = yes read only = no create mask = 0777 directory mask = 777
-
[hartmutand[hartmut-E]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 arranged under/home/D. The second is the path to a mounted external SDD on the Linux PC, which can be accessed via network also from Windows. The directorydbelowE/dis used because in the mounted state of the SSD with access problems view to/homeneeds timeouts till the problem is detected or fixed. This is especially for mounted network drives, see next. -
force user = hartmutis the user name which is used for access (may be non identically with the share name, but for the first connection often it is the share for the same user. This is essential and was missing in other examples! -
The rest may be obvious, it’s copied from some examples.
2.3. check whether Samba is installed, check the status
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 E:\ subst E: /D if exist E:\ net use R: /delete net use E: \\%IP%\hartmut-E /PERSISTENT:NO /USER:hartmut
-
IP is set as environment variable with
192.168.2.70as the IP from the Linux PC. -
ping the destination to see whether it is reachable in network.
-
It may be possible that E: is mounted in Windows, with a subst or a network drive before, remove the subst or net use before.
-
On
net use: The firsthartmut-Eis the share name. -
Whether
/USER:hartmutis used - not tested yet. It is not sufficient to determine the user on the Linux side. It is sufficient for Windows networt 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-68-D-U.sh:
sudo umount /home/U/d ls /home/U ##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) //192.168.1.68/D /home/U/d sudo mount -t cifs -o user=hartmut,uid=$(id -u),gid=$(id -g) //192.168.1.68/D /home/U/d ls /home/U/d
-
The
Dafter the ip//192.168.1.68/is the network name in windows for the network drive (maybe a longer name, but for me it is the subst drive D:). -
/home/U/dis the directory name on linux where the file tree is shown. The directorydbelowU/dis used because in the mounted state of the SSD with access problems view to the network source (cable unplugged, computer switched off) the access to/homeneeds timeouts till the problem is detected or fixed.
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/U/d sudo umount /home/W/d
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.