You are not logged in.

#1 2020-10-14 13:08:01

Xwang
Member
Registered: 2012-05-14
Posts: 212

[Solved] Sharing an USB disk when mounted with samba on LAN

Hi to all!
I would like to share an USB disk when mounted on the LAN using samba so that to be able to access to its contents from my android devices.
I've installed the kdenetwork-filesharing package and I've configured the samba server so that this is the output of testparm -s:

Load smb config files from /etc/samba/smb.conf
Loaded services file OK.
Weak crypto is allowed
Server role: ROLE_STANDALONE

# Global parameters
[global]
        bind interfaces only = Yes
        disable spoolss = Yes
        dns proxy = No
        interfaces = lo enp3s0f1
        load printers = No
        log file = /var/log/samba/%m.log
        max log size = 50
        printcap name = /dev/null
        server role = standalone server
        server string = Samba Server
        show add printer wizard = No
        idmap config * : backend = tdb
        hosts allow = 192.168.1. 127.
        printing = bsd

When I try to share the mounted USB drive from dolphin using kdenetwork-filesharing, nothing happens and I get the following lines in the journalctl:

ott 14 14:55:18 MYPCNAME dolphin[2883]: kf.kio.core: We got some errors while running testparm "Weak crypto is allowed"
ott 14 14:55:19 MYPCNAME dolphin[2883]: kf.kio.core: We got some errors while running 'net usershare add' ("usershare", "add", "hdd500gb", "/run/media/MYUSERNAME/ext2-1tb/hdd500gb", "", "Everyone:d,MYUSERNAME:r,guest:d", "guest_ok=n")
ott 14 14:55:19 MYPCNAME dolphin[2883]: kf.kio.core: "net usershare: usershares are currently disabled\n"

I've read https://wiki.archlinux.org/index.php/sa … Usershares , but there are some things that are not clear to me:
1) Can I can share the USB using usershare? In such a case what should I select as directory for usershares?
2) I want to be the only one to be able to access to the shared folder. My android devices when I try to connect ask me for a samba user name and password. Is it correct that I use MYUSERNAME (the user with which I login to the computer and as password the one I've set with smbpasswd -a MYUSERNAME ?
3) Is there any way to automatize the sharing of the USB folder when it is connected and the umount of the sharing folder when the USB is unplugged? In an ideal world I would like to have the samba serve running only when I connect that device. Any suggestion?

Last edited by Xwang (2020-11-03 13:05:33)


I'm still learning English so please excuse me if my English is not good enough and feel free to correct me via PM if you want.

Offline

#2 2020-10-31 11:19:59

Xwang
Member
Registered: 2012-05-14
Posts: 212

Re: [Solved] Sharing an USB disk when mounted with samba on LAN

I cannot access to the shared samba folder from other pc in my lan.
The only way I manage to connect is on the pc which runs the samba server using the loopback 127.0.0.1 address.
Using the machine IP (192.168.1.200) it is impossible to connect even on the pc running the server.
Am I missing something?
This is my smb.conf (I've deleted all the comments):

[global]
   workgroup = WORKGROUP
   server string = Samba Server
   server role = standalone server
   hosts allow = 192.168.1.  127.
   log file = /var/log/samba/%m.log
   max log size = 50
   bind interfaces only = yes
   interfaces = lo enp3s0f1 
   load printers = no
   printing = bsd
   printcap name = /dev/null
   disable spoolss = yes
   show add printer wizard = no

# A private directory, usable only by andreak. Note that andrea does not require write
# access to the directory.
[hdd500gb]
   comment = hdd500gb folder on ext2-1tb
   path = /run/media/andreak/ext2-1tb/hdd500gb/
   valid users = andreak
   public = no
   writable = no
   printable = no

This is the output of smbclient -L localhost -U% :

        Sharename       Type      Comment
        ---------       ----      -------
        hdd500gb        Disk      hdd500gb folder on ext2-1tb
        IPC$            IPC       IPC Service (Samba Server)
SMB1 disabled -- no workgroup available

I'm still learning English so please excuse me if my English is not good enough and feel free to correct me via PM if you want.

Offline

#3 2020-10-31 21:43:59

papavlos
Member
Registered: 2017-09-23
Posts: 41

Re: [Solved] Sharing an USB disk when mounted with samba on LAN

Did you add andreak as samba user?
Have a look here

Offline

#4 2020-11-01 06:01:47

Xwang
Member
Registered: 2012-05-14
Posts: 212

Re: [Solved] Sharing an USB disk when mounted with samba on LAN

Yes I did.
It seems that I have to restart the samba server every time the USB disk is connected in order to be able to connect to the shared folder.


I'm still learning English so please excuse me if my English is not good enough and feel free to correct me via PM if you want.

Offline

#5 2020-11-01 07:33:52

Xwang
Member
Registered: 2012-05-14
Posts: 212

Re: [Solved] Sharing an USB disk when mounted with samba on LAN

My idea is to create a systemd service which exec a systemctl restart smb.service everytime the usb disk is mounted. But that command asks for the insertion of the sudo password in a popup window.
Is it possible to avoid that and restart the samba server as a user?


I'm still learning English so please excuse me if my English is not good enough and feel free to correct me via PM if you want.

Offline

#6 2020-11-01 22:12:44

papavlos
Member
Registered: 2017-09-23
Posts: 41

Re: [Solved] Sharing an USB disk when mounted with samba on LAN

AFAIK samba service requires root, so sudo is required.
You can modify the /etc/sudoers file to avoid sudo asking for password. But please keep in mind that you open a high security vulnerability by doing that.

Or, create and run on root account the mentioned systemd service for restarting samba. Then sudo would not be required.

Last edited by papavlos (2020-11-01 22:15:30)

Offline

#7 2020-11-02 08:11:34

Xwang
Member
Registered: 2012-05-14
Posts: 212

Re: [Solved] Sharing an USB disk when mounted with samba on LAN

papavlos wrote:

AFAIK samba service requires root, so sudo is required.
You can modify the /etc/sudoers file to avoid sudo asking for password. But please keep in mind that you open a high security vulnerability by doing that.

Or, create and run on root account the mentioned systemd service for restarting samba. Then sudo would not be required.

Thank you for your help.
I've seen that adding something like this:

xwang ALL=(ALL) NOPASSWD: /usr/bin/systemctl restart smb.service

in the sudoers file should give to the user the ability to execute only the restart of the smb.service .

However firstly I will try to move the systemd service from ~/.config/systemd/user/ to /etc/systemd/system/ and see if it solve the issue.


I'm still learning English so please excuse me if my English is not good enough and feel free to correct me via PM if you want.

Offline

#8 2020-11-02 08:40:58

Xwang
Member
Registered: 2012-05-14
Posts: 212

Re: [Solved] Sharing an USB disk when mounted with samba on LAN

I confirm that moving the systemd service (the one which executes samba server restart every time the USB drive is mounted) from ~/.config/systemd/user/ to /etc/systemd/system/ solves the issue of having to insert the password everytime yhe USB drive is mounted.


I'm still learning English so please excuse me if my English is not good enough and feel free to correct me via PM if you want.

Offline

Board footer

Powered by FluxBB