Script to automagically mount a samba shared folder in antiX

Forum Forums General Software Script to automagically mount a samba shared folder in antiX

  • This topic has 24 replies, 4 voices, and was last updated Mar 17-1:10 am by olsztyn.
Viewing 15 posts - 1 through 15 (of 25 total)
  • Author
    Posts
  • #78786
    Member
    PPC

      For those that have been keeping up with my posts here in the forum, my main antiX project right now is FT10 – that aims to both give antiX a more modern look and feel, and still use as little resources as possible and provide some extra amenities- the current FT10 beta provides some extra scripts, including one to configure zzzfm to look more streamlined, and have some extra features, like a trash can and recent files. Thanks to madibi’s request, last night I tried to figure out how to set up a network share, and how to easily mount it in zzzfm. I’m aware that antix includes “connectshares”, but I wanted something that did not require any configuration- I wanted to have a list of all networked shared folders, that I could mount with a single click- some Linux file managers do provide that, but implementing this from the ground up (in the form of a script that could be summoned from zzzfm) was harder than I though.

      -the script is available here: https://gitlab.com/antix-contribs/ft10-transformation/-/raw/main/connect_to_existing_network_shares.sh
      -Dependencies: arp-scan, smbclient (on my computer this dependencies take about 15mb of disk space, or so…)

      How to use the script:
      1- Configuration:
      1.1- open an empty text file
      1.2- copy the text in https://gitlab.com/antix-contribs/ft10-transformation/-/raw/main/connect_to_existing_network_shares.sh and paste it to the text file
      1.3- save it with a name, something like “connect_to_existing_network_shares.sh” (without the quotation marks), in your user’s home folder
      1.4- using zzzfm navigate to your home folder, right click the script you just created >Propreties > Permitions > and check, at least the first “Execute” field > click “ok”
      1.5- Don’t forget to make sure all the required dependencies are installed. You can do that doing this in the terminal:
      sudo apt install -y arp-scan smbclient
      and enter your password, if asked to…

      2- Running the script:
      right click the script, choose to execute it.
      If all goes well, the script will present you with the IP’s of all devices connected to your network. click the IP of the device that hosts your network shared folder. If only one shared folder is detected, the script will try to mount it. If more than one shared folder is detected, a new window will allow you to select which one you want to mount. If a password is required to access that folder, enter it, when prompted to in a terminal window that asks for it.
      Once again, if all goes well, you’ll see your shared folder displayed in zzzfm…

      How useful do you folks think this will be? My aim, if it works well, is to include a new Bookmark in FT10’s zzzfm- something like “Shared folders”, that launches this script…
      It’s only the first beta, without any checks, etc… As always, all feedback is welcome.

      P.

      Edit: if you want to run the script withou having to enter your sudo password (BE CAREFULL DOING THIS, DO IT AT YOUR OWN RISK):
      Menu > Terminal:

      sudo geany /etc/sudoers

      and add, in the end of the file:

      user host = (root) NOPASSWD: /usr/share/arp-scan
      user host = (root) NOPASSWD: /usr/sbin/arp-scan

      save the file, and restart your session. Now you don’t have to enter the password to use the script

      • This topic was modified 1 year, 1 month ago by PPC.
      #78796
      Member
      olsztyn
        Helpful
        Up
        0
        ::

        right click the script, choose to execute it.
        If all goes well, the script will present you with the IP’s of all devices connected to your network. click the IP of the device that hosts your network shared folder. If only one shared folder is detected, the script will try to mount it. If more than one shared folder is detected, a new window will allow you to select which one you want to mount. If a password is required to access that folder, enter it, when prompted to in a terminal window that asks for it.

        Thanks @PPC…
        I kind of like this idea. Such script provides a useful way to connect to SMB shares in a flexible way, as it shows available shares. In principle Connectshares does this but I might like your script too.
        I have tested your script and I have the following observations, possibly for your consideration:
        – SMBClient and arp-scan include a relatively large number of dependencies, which to install on antiX, not previously included.
        – If share is SMB 1.0 then the pop-up window shows up empty – no shares, for such IP address. The script would need to account for shares that are under SMB 1.0, not just 2.0.
        – The script does not seem to allow to log-in to share with complete credentials. It does ask for the password but it assumes the username in antiX, which is usually not the case. SMB provides security and requires both SMB defined username and password to access shares.

        So far I have my shares pre-defined in fstab and mount them just by mount command, like ‘mount S’, which makes zzz see that S share in FM. However your script would further allow to mount them on the fly without defining in fstab.
        Thanks and Regards…

        • This reply was modified 1 year, 1 month ago by olsztyn.

        Live antiX Boot Options (Previously posted by Xecure):
        https://antixlinuxfan.miraheze.org/wiki/Table_of_antiX_Boot_Parameters

        #78804
        Member
        madibi
          Helpful
          Up
          0
          ::

          PPC mágico!! Muito obrigado!
          Thx very much. I really appreciate how attentive you are to the needs of others.

          I think that this utility may help some former win user not to miss their old OS.
          How much does it costs in terms of more ram used? This may be the unique minus of this utility.

          For sure I’ll try it before the week end and I’ll let you know 🙂

          Once I saw the topic concerning the fact that the FM don’t display the shares available on the network. Now I don’t find it.
          There it was reported that also installing Thunar (or Pcmanfm), that on xfce (lxde) shows the shares, in antix it doesn’t.

          That was convincing me that may/should exist some parameter under antix that “if I change some flag”, it let things working as done by your program.
          Unfortunately I could never find something that can help me.

          I personally don’t like connectshares, what I usually do is to type on the bar of zzzfm the address (e.g.: smb://192.168.1.234/madibi/), it asks me handle and pw, and I connect. There I can also bookmark the connection. Unfortunately not very often, the DHCP changes the ip address, so i have to repeat the procedure.

          #78823
          Member
          PPC
            Helpful
            Up
            0
            ::

            The current beta version of the script is here: https://gitlab.com/antix-contribs/ft10-transformation/-/raw/main/connect_to_existing_network_shares56.sh

            Changes:
            -Now the script only external dependency (not included by default in antiX full) is smbclient
            -The network shares detection is slower (it ranges from 5 – 50 seconds on my tests), but, as far as I can tell, it’s now flawless, my initial attempt failed to detect shares sometimes…
            -because the process now may take more time, I added a pulsating window, showing that the script is working…
            -The script looks a bit more polished- with better looking windows, and it even checks if the computer is connected to a network, before starting.

            @olsztyn -Thanks for the input: the script now has much less dependencies (it no longer requires arp-scan), but I found no way, that works on antiX, to detect a samba shared folder other than using SMBClient…
            It’s been only a couple of days since I began experimenting with shared folders (boy, having a shared folder is a time saver, when testing scripts on 2 computers, I wish I got into that before), so I have, at the moment, no idea why the script does not work with SMB 1.0- if it was an arp-scan problem, it’s now solved, since I don’t use it anymore… if it’s a smbclient problem, I have no way to address that…
            -About the user/password- hum… since I only recently started using network folders, I though this way: for simple stuff, no password is the way to go, to share documents or scripts between my computers. For more sensitive stuff, I though it made sense using my antiX password- one less password to have on my memory… But it’s not a big deal- the difficult part of the process is finding out the available complete addresses of the shared folders ( ip+folder_name ). Once we have that (and we do), we can modify the script to show a log in window, so the user can enter the user,workgroup and password, and then the script can mount the shared folder and show it in zzzfm…

            @madibi – since I haven’t used other file managers in years, I can’t help you with any other fm other than zzzfm/rox, but I think there are file system dependencies that you do have to install to have certain features in thunar… probably this includes network shares related stuff…
            Edit: on the script’s use of system resources – don’t worry- it’s not only tiny, but once you connect to the network share, the script exits, and you are only using zzzfm (all the script tries to do is to automate the process of entering the share’s address in zzzfm, nothing more).
            What frustrated me was that most tutorials about shared folders in Linux take for granted that you always now the ip address of the computer that hosts the shared folder, and the name of the share folder – they always say “just enter the ip”- and I kept thinking- “ok, but most people have no idea what their computer’s ip is- most people don’t even know what that really is, and that the “host” pc has a different ip from the pc that is connecting to it’s shared folder- on Windows, and other Linux’s, it’s easy- you have a list of available network shares and only have to click the one you want- no need to read ip’s etc!”… That is the functionality I want to make available in antiX- even if it’s faster just typing your ip and shared folder name in the address bar, if you know that by heart, on the long run it’s faster to use a script like this, and once you connect to your shared folder, just bookmark it. If it’s ip changes, just delete the bookmark and run the script again… 🙂

            P.

            • This reply was modified 1 year, 1 month ago by PPC.
            • This reply was modified 1 year, 1 month ago by PPC.
            #78827
            Member
            olsztyn
              Helpful
              Up
              0
              ::

              It’s been only a couple of days since I began experimenting with shared folders (boy, having a shared folder is a time saver, when testing scripts on 2 computers, I wish I got into that before), so I have, at the moment, no idea why the script does not work with SMB 1.0- if it was an arp-scan problem, it’s now solved, since I don’t use it anymore… if it’s a smbclient problem, I have no way to address that…

              I think SMB 1.0 requires that this version must be specified explicitly, otherwise SMB defaults to version 2.0. This is also the way it must be specified in Connectshares Configuration. I learned this from SamK in this forum some two years ago so this is an opportunity to mention credit to SamK for developing Connectshares… If SamK is still connected to this forum he might be willing to share some additional advice for perfecting this script…

              Live antiX Boot Options (Previously posted by Xecure):
              https://antixlinuxfan.miraheze.org/wiki/Table_of_antiX_Boot_Parameters

              #78828
              Member
              PPC
                Helpful
                Up
                0
                ::

                @olsztyn – thanks for the extra info!

                I made a faster version of the script, also available in gitlab, that depends on the “nmap” package for performing a faster search of all available ips- in my tests the script runs on 2 – 20 seconds- so, it seems to be perfectly usable…
                Later I’ll try to check out the SMB 1.0 situation, and also how to add a window to enter the credentials – my problem is detecting when the shared folder does not require password, and avoid that extra step when it’s not needed…

                P.

                #78862
                Member
                PPC
                  Helpful
                  Up
                  0
                  ::

                  OK, last night I polished the script. It’s available, under a new name, here: https://gitlab.com/antix-contribs/ft10-transformation/-/raw/main/my_network_neighborwood_0.9beta.sh

                  Changes:
                  -The script now requires this packages to be installed: smbclient, nmap
                  – new GUI window to enter credentials (if the shared folder does not require a password, just close the window asking for credentials and the share will be instantly mounted)

                  To do:
                  -Add check for dependencies and offer to install them, if needed
                  -Add support for Smb v1 (eventually)

                  The script now does exactly what I though every OS needs: it checks, in a fast way, the network for any existing (samba) shared folders and offers to mount them, all in GUI format (but, if you launch the script in the terminal, you’ll get lots of info about what the script is doing).
                  There is almost no need for localization- the only text is in the error message windows, if no network or no network shares are detected… I can even replace that text with some nice icons if I find any…

                  Edit:
                  I forgot to say this – I think connectshares, despite being a great automatization tool lacks something my script has- a way to find out existing (even not mounted) shared folders. You can run my script via the terminal and get the correct ip and share name to add to the connectshares config file – this way activating connectshares does automatically mount the shares… My script does not aim to automate the mounting process of shared folder, only to be an easy GUI way to discover and mount them- it can be tedious to keep entering the user name (the script assumes it’s the same as your session’s user, but you can edit that field), and password… Future versions can have a config file, that store your credentials for each share and automatically insert them on the corresponding user/password fields, so you only need to click “ok” or press enter on the log in window…- but I dislike that option because it would store your password on a plaint text file (just like connectshares, I guess), and if you have a password to access your network shares, it probably is because you don’t want anyone snooping around… right? So, I stand by my initial decision: open shared folder (without password) for stuff I don’t mind sharing, and password protected folders for sensitive stuff (and I have to always enter my password to access them)

                  P.

                  • This reply was modified 1 year, 1 month ago by PPC.
                  #78864
                  Member
                  olsztyn
                    Helpful
                    Up
                    0
                    ::

                    I think connectshares, despite being a great automatization tool lacks something my script has- a way to find out existing (even not mounted) shared folders. You can run my script via the terminal and get the correct ip and share name to add to the connectshares config file – this way activating connectshares does automatically mount the shares… My script does not aim to automate the mounting process of shared folder, only to be an easy GUI way to discover and mount them- it can be tedious to keep entering the user name (the script assumes it’s the same as your session’s user, but you can edit that field), and password…

                    Hi PPC…
                    I have tested your new version on a range of my NAS servers, SMB1 and SMB2 hosting various SMB shares.
                    The new script works nicely on SMB2 and maps shares accordingly. Authentication security works. Great progress!
                    Just additional observations:
                    – Shares on SMB1 servers are not even listed. As you mentioned, it is still outstanding.
                    – In authentication window it fills in a ‘default’ user as used in antiX. That would almost never be the same username to access SMB. That would be better to leave blank, as SMB servers have their own user names defined, unlikely matching any of client ones.
                    – It would be great to map connected SMB shares to a user folder, but not necessarily needed in a ad-hoc connection.

                    Very nice accomplishment. Understandably some more work is needed, but ones done it will be a great addition to antiX and perhaps somehow integrated into antiX by default, if antixcapitalista agrees…
                    Thanks much and Regards…

                    Live antiX Boot Options (Previously posted by Xecure):
                    https://antixlinuxfan.miraheze.org/wiki/Table_of_antiX_Boot_Parameters

                    #78867
                    Member
                    PPC
                      Helpful
                      Up
                      0
                      ::

                      I took a look a cursory look at the smb1 problem at lunch time… According to this: https://askubuntu.com/questions/1265923/configuring-20-04-samba-for-smbv1 , “since Samba 4.11 it no longer allows support for NT1 (SMB1)”. The samba version I have installed is “4.9.5+dfsg-5+deb10u3″…
                      This web page: https://www.cyberciti.biz/faq/how-to-configure-samba-to-use-smbv2-and-disable-smbv1-on-linux-or-unix/ seems to point out that using smb v.1 is insecure…

                      @olsztyn – thanks for the “field test”… The thread I pointed to explains how to allow smb v.1, but it points to the fact that that version is no longer supported? I don’t really understand much about samba shares, but… If using v.1 is really discouraged, maybe I should not try to implement it in the script… since you do use it, what are your thoughts on the subject?
                      About the “default” user name – I took the care to make the “user” field, by default, be the same as the OS user name, just well… because that’s my particular case, and it also shows, clearly what’s supposed to be on that field. When you begin typing, you instantly overwrite that field’s content, there’s even no need to click that field… But you can adapt the script, if you intend to use it (and not just test it)- Open the script and, in the line that starts with “entry=”, probably is around line 86, delete this variable “$USER”, and save the script. From now on, by default, the user field will show up empty by default…

                      P.

                      • This reply was modified 1 year, 1 month ago by PPC.
                      #78870
                      Member
                      olsztyn
                        Helpful
                        Up
                        0
                        ::

                        @olsztyn – thanks for the “field test”… The thread I pointed to explains how to allow smb v.1, but it points to the fact that that version is no longer supported? I don’t really understand much about samba shares, but… If using v.1 is really discouraged, maybe I should not try to implement it in the script… since you do use it, what are your thoughts on the subject?

                        Just to clarify:
                        SMB 1.0 is an older version and by nowadays standards it has a security issue on SMB server. But it is still widely used as many users have SMB 1.0 NAS servers. Most of my SMB servers are SMB 2.0, which are most common, but I also have two SMB 1.0 NAS servers. But it is not about me, as many other users, particular individual home networks are likely to have SMB 1.0 NAS, such as one drive network drives, such as Seagate, Netgear, WesternDigital… Many of these are SMB 1.0, particularly older ones. However warranty usually expired, so manufacturers do not care to provide updated firmware…

                        Every system, even Windows 10 allows connecting SMB 1.0, just has to be enabled explicitly. As much as I know, on Linux it requires SMB 1.0 version to be specified in configuration, such as in Connectshares. SamK had very detailed explanation that such parameter needs to be specified.
                        For me it does not matter too much if your utility supports SMB 1.0, but for completeness it would be good to have this option in such function.
                        If SamK, the creator of Connectshares is still in this forum (I have not seen his posts recently) perhaps he would have some additional suggestions…
                        Thanks again…

                        • This reply was modified 1 year, 1 month ago by olsztyn.

                        Live antiX Boot Options (Previously posted by Xecure):
                        https://antixlinuxfan.miraheze.org/wiki/Table_of_antiX_Boot_Parameters

                        #78872
                        Member
                        PPC
                          Helpful
                          Up
                          0
                          ::

                          I hunted down Samk’s post – you seem to be referring to this: https://www.antixforum.com/forums/topic/connectshares-does-it-still-work/page/2/#post-34015

                          If you can, please adapt my script and test it with you smb 1 shares (and also with smb2, to see if doing that is “universal”, or just allows access to smb shares)

                          edit this line, near the end of the script:
                          udevil mount -t cifs -o username=$username,password=$password $share

                          and change it to this:

                          udevil mount -t cifs -o username=$username,password=$password $share vers=1.0

                          Check if it runs… if not, please try to position the “vers=1.0” before the username…
                          Thanks

                          P.

                          • This reply was modified 1 year, 1 month ago by PPC.
                          #78875
                          Member
                          olsztyn
                            Helpful
                            Up
                            0
                            ::

                            Check if it runs… if not, please try to position the “vers=1.0” before the username

                            Unfortunately neither of such combinations I tried appears to show SMB 1 shares.
                            I am not sure if this will help but this is what I have in fstab for SMB 1:
                            //192.168.0.6/Video /home/demo/B cifs username=francis,vers=1.0,noauto,user 0 0

                            I tried ‘vers=1.0’ after password spec in your script, but that did not work either. I think Connectshares code is a great resource, but perhaps specification changed recently in smbclient – I did not get around to research this yet.
                            All SMB 2.0 shares are found and listed though…

                            Live antiX Boot Options (Previously posted by Xecure):
                            https://antixlinuxfan.miraheze.org/wiki/Table_of_antiX_Boot_Parameters

                            #78879
                            Member
                            olsztyn
                              Helpful
                              Up
                              0
                              ::

                              @ PPC:
                              Searching internet for smbclient specification for SMB 1.0 it appears this worked for me as a command for smbclient:

                              smbclient -L //<hostname>/<folder> –option=’client min protocol=NT1′

                              I am trying to incorporate this protocol option in your script…

                              Update:
                              I am still trying to incorporate client min protocol option for smbclient into your script. Not sure of udevil syntax. Just to confirm though – smbclient successfully executes this option.
                              However, even if specifying SMB 1 as minimum protocol for the script becomes too much of figuring out syntax I suggest just proceed with the already working script for SMB 2.0 as minimum. This might cover a majority of users.
                              Thanks again…

                              • This reply was modified 1 year, 1 month ago by olsztyn.

                              Live antiX Boot Options (Previously posted by Xecure):
                              https://antixlinuxfan.miraheze.org/wiki/Table_of_antiX_Boot_Parameters

                              #78887
                              Member
                              PPC
                                Helpful
                                Up
                                0
                                ::

                                @olsztyn – once again, thanks for your efforts…
                                Just to see if you can use the script with sbm v.1, if you want, replace the
                                the smbclient line (around line 47) with this one:

                                smbclient -N -L $line -option='client min protocol=NT1' | sed '/Printer Drivers/d' | grep "Disk" | cut -d' ' -f1 >/tmp/ccc

                                Using it that way still detects my smb folders and allows me to mount them…

                                P.

                                #78888
                                Member
                                olsztyn
                                  Helpful
                                  Up
                                  0
                                  ::

                                  Indeed, I tried this before and just did again. Unfortunately the resulting list is still missing the SMB 1.0 server shares.
                                  However, since smbclient was able to detect it successfully from command line as I reported previously, it must be just a matter of syntax.
                                  All SMB 2.0 severs are listed perfectly along with their shares.
                                  Great accomplishment as it is already…

                                  Live antiX Boot Options (Previously posted by Xecure):
                                  https://antixlinuxfan.miraheze.org/wiki/Table_of_antiX_Boot_Parameters

                                Viewing 15 posts - 1 through 15 (of 25 total)
                                • You must be logged in to reply to this topic.