How do I mount a CIFS share?





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







60















I'm using Ubuntu 11.10, and am trying to mount a freenas server. I have the server set to share in cifs and nfs with no luck.



I have tried smbmount //192.168.1.### /mnt/



I am not new to Ubuntu but am nowhere near a power user, so I'd prefer a GUI option if available.



How do I mount a cifs share in 11.10?










share|improve this question































    60















    I'm using Ubuntu 11.10, and am trying to mount a freenas server. I have the server set to share in cifs and nfs with no luck.



    I have tried smbmount //192.168.1.### /mnt/



    I am not new to Ubuntu but am nowhere near a power user, so I'd prefer a GUI option if available.



    How do I mount a cifs share in 11.10?










    share|improve this question



























      60












      60








      60


      20






      I'm using Ubuntu 11.10, and am trying to mount a freenas server. I have the server set to share in cifs and nfs with no luck.



      I have tried smbmount //192.168.1.### /mnt/



      I am not new to Ubuntu but am nowhere near a power user, so I'd prefer a GUI option if available.



      How do I mount a cifs share in 11.10?










      share|improve this question
















      I'm using Ubuntu 11.10, and am trying to mount a freenas server. I have the server set to share in cifs and nfs with no luck.



      I have tried smbmount //192.168.1.### /mnt/



      I am not new to Ubuntu but am nowhere near a power user, so I'd prefer a GUI option if available.



      How do I mount a cifs share in 11.10?







      mount windows nfs cifs






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Aug 8 '17 at 22:52









      muru

      1




      1










      asked Feb 3 '12 at 6:58









      KYLEKYLE

      301133




      301133






















          8 Answers
          8






          active

          oldest

          votes


















          80














          There is pyNeighborhood which is a gui for mounting samba shares and available in the software centre for download.



          There is a good article located here on how to set it up and use it.



          First install cifs utils



          sudo apt-get install cifs-utils




          Alternatively, the basic terminal command is :



          mount -t cifs -o username=USERNAME,password=PASSWD //192.168.1.88/shares /mnt/share


          If you'd like to see your mount in Nautilus it would be good to create a subfolder first in /media/USERNAME/ for example:



          mkdir /media/paul/cifsShare


          also, password could ommited in the mount command for example (will also demonstrate file/folder modes):



          sudo mount -t cifs //nas-server/cifsShare /media/paul/cifsShare -o username=paulOnNAS,iocharset=utf8,file_mode=0777,dir_mode=0777,soft,user,noperm


          in this case you'll be asked for the password (actually for 2 passwords) on the mounting moment.



          Have a read through the Samba documentation here on how to do it and set it up correctly to mount on start up etc.






          share|improve this answer





















          • 2





            is there a way to mount the samba share without 1) hard coding the password and 2) having to be root?

            – mcExchange
            Jan 25 '16 at 14:18






          • 1





            @mcExchange root is needed and you can use smb credentials file to protect you credentials

            – adampski
            Feb 29 '16 at 13:14






          • 4





            also make sure you have cifs-utils installed: sudo apt-get install cifs-utils. For more info this ubuntu help doc is great.

            – Marco Pashkov
            Mar 31 '16 at 5:20






          • 1





            pyNeighborhood gives me segmentation fault when started over ssh in ubuntu 14.04

            – Pavel Niedoba
            May 8 '16 at 22:12






          • 1





            @MarcoPashkov cifs-utils is what got me up and going. None of this would work otherwise. This should be directly included in the answer.

            – rubynorails
            Jul 5 '16 at 19:32



















          12














          It's as map7 said, but if you don't want to use root permissions every time you change a file on the drive, then you'll have to mount to a user folder, and make sure the gid and uid are set to your username.



          The command setting them:



          mount -t cifs -o username=USERNAME,password=PASSWD,uid=$USER,gid=$USER //192.168.1.88/shares ~/mnt/share


          Note that mnt folder was created in ~/mnt/share instead of /mnt/share.



          Also you can leave out password=PASSWD if you want it to prompt you instead of you having it in the command, which is potentially stored in your shell's history:



          mount -t cifs -o username=USERNAME,uid=$USER,gid=$USER //192.168.1.88/shares ~/mnt/share





          share|improve this answer





















          • 1





            Make a more complete answer, with some examples and I'll upvote :)

            – storm
            Dec 21 '16 at 15:02



















          5














          1) My samba share shows in Caja (the ubuntu 16.04 „explorer“) as



          smb://thinkpad/ddrive/


          This is a good lithmus test, there are no connection/path issues.



          (caveat: If you get asked by caja about password credentials from your windows machine, you might want to switch Domain from WORKGROUP to the name of the machine, i.e. ‘thinkpad’. Then the truly local login credentials of your drive should do.)



          2) If that works, here comes the command:



          sudo mount -t cifs -o username=frank //thinkpad/ddrive /mnt/ddrive



          • Make sure beforehand, /mnt/ddrive exists as an empty directory.

          • You cold also add a ,password=supersecret directly (no space) after username=, but you can also wait for being prompted, when you enter the command.






          share|improve this answer



















          • 2





            It took me a bit to figure out, where I can type in the smb://.... path in Nemo / Linux Mint 18, but actually it's quite simple: if the path input box is not visible, enable it in the View menu.

            – Pedi T.
            Aug 10 '17 at 16:32



















          3














          I disagree with the claim that root is always necessary to make cifs connections go. It is true, it is always needed for CLI smbmount, but a file manager such as nautilus has ability to mount a cifs share and it is not necessary to be root.



          I don't use Gnome, but I still have Nautilus installed. Run this in a terminal to prevent having it try to take over the desktop



          $ nautilus --no-desktop &


          In Ubuntu 16.04, left side tree menu has "Connect to Server" on the bottom. Click that, the suggestion is type "smb://foo.example.com". smb is old word for "cifs", and if you put in your server and share with smb:// at beginning, connection does work! I promise. If your share is a named thing, it is required after a slash, "smb://foo.example.com/myshare".



          I've used other file managers in same way. Protocol has to be "smb://".






          share|improve this answer































            3
















            1. You can put all those details in /etc/fstab so you can have directories mounted on system startup. If windows or SMB server is on IP address 192.168.1.1



              /etc/fstab
              //192.168.1.1/SharedFolder/ /mnt/linux_smb cifs username=winuser,password=TopSecret 0 0



            2. Create directory as linux mount point



              mkdir /mnt/linux_smb
              chmod 755 /mnt/linux_smb



            3. For the first time mount this manually



              mount -a



            4. Eventual errors can be found by



              dmesg | tail 







            share|improve this answer































              3
















              1. There is specific issue possible and very frustrating to resolve when versions of CIF/SMB are not compatible between Linux and Windows.
                In that case you can just make minor chnage in fstab line adding "vers=2.1"



                So, if Windows or SMB server is on IP address 192.168.1.1



                /etc/fstab

                //192.168.1.1/SharedFolder/ /mnt/linux_smb cifs vers=2.1,username=winuser,password=TopSecret 0 0


              2. Steps 2, 3 and 4 remains the same as in previous answer.







              share|improve this answer































                1














                I put together a little script (it's meant for Fedora though) to mount the CIFS filesystem from the command line and create/delete a test file. May be of some use:



                #!/bin/bash
                # Passes https://www.shellcheck.net/

                set -o nounset

                # See
                # https://wiki.samba.org/index.php/Mounting_samba_shares_from_a_unix_client
                # https://access.redhat.com/solutions/448263
                # and also
                # https://serverfault.com/questions/309429/mount-cifs-credentials-file-has-special-character

                # One needs to run "yum install cifs-utils" to have the kernel module, man page
                # and other stuff.

                rpm --query cifs-utils > /dev/null

                if [[ $? != 0 ]]; then
                echo "Package cifs-utils is not installed -- exiting" >&2
                exit 1
                else
                ver=$(rpm --query cifs-utils)
                echo "Package $ver exists ... good!" >&2
                fi

                # Where to find credentials? Use the "credential file" approach, which
                # we call "authfile". Example content (w/o the leading #) below.
                # Make sure there are no spaces around '=' (this is different than
                # for "smbclient" which can deal with spaces around '='.)
                # ----8<------8<----------------
                # username=prisoner
                # password=KAR120C
                # domain=VILLAGE
                # ----8<------8<----------------
                # Trailing empty lines will lead to (harmless) error messages
                # "Credential formatted incorrectly: (null)"

                authfile='/etc/smb.passwd' # Make sure read permissions are restricted!!

                # Server to contact.
                # In the UNC path, we will use DNS name instead of the (more correct?)
                # NetBIOS name.
                # mount.cifs manpage says: "To mount using the cifs client, a tcp name
                # (rather than netbios name) must be specified for the server."

                server_dns=thedome.example.com

                # The name of the connecting client, just to be sure (probably useless)

                client_nbs=$(hostname --short | tr '[:lower:]' '[:upper]')

                if [[ -z $client_nbs ]]; then
                client_nbs=UNKNOWN
                fi

                # Connect to a certain service (which is a fileservice)
                # and then switch to the given directory.
                # Instead of appending $directory to form the complete UNC
                # (Uniform Naming Convention) path, one could also use the option
                # "prefixpath".
                # If there is no need to mount a subdirectory of the service,
                # the UNC would just be unc="//$server_dns/$service_name"

                service_name='information'
                directory='PERSONALDATA'

                unc="//$server_dns/$service_name/$directory"

                # Finally, we will mount the CIFS filesystem here (the
                # permissions on that node are not directly of interest)

                mntpoint=/mnt/portal

                if [[ ! -d "$mntpoint" ]]; then
                mkdir "$mntpoint"
                if [[ $? != 0 ]]; then
                echo "Could not create mountpoint '$mntpoint' -- exiting" >&2
                exit 1
                fi
                fi

                # Only this user will be able to access the mounted CIFS filesystem

                user=number6
                group=number6

                # Try to mount this so that only user "number6" can access it

                mount -t cifs
                "$unc"
                "$mntpoint"
                --read-write
                --verbose
                -o "credentials=$authfile,uid=$user,gid=$group,netbiosname=$client_nbs,file_mode=0660,dir_mode=0770"

                res=$?

                if [[ $res != 0 ]]; then
                echo "Mount failed!" >&2
                echo "Return code $res; more info may be in kernel log or daemon log" >&2
                echo "Try 'journalctl SYSLOG_FACILITY=0' or 'journalctl SYSLOG_FACILITY=3'" >&2
                echo "...exiting" >&2
                exit 1
                fi

                # Check permissions on the mount point

                stat=$(stat --format="group=%G user=%U access=%A" "$mntpoint")
                soll="group=$group user=$user access=drwxrwx---"

                if [[ $stat != "$soll" ]]; then
                echo "Incorrect permissions on root of '$mntpoint'" >&2
                echo "Expected: $soll" >&2
                echo "Obtained: $stat" >&2
                echo "...exiting" >&2
                umount "$mntpoint"
                exit 1
                fi

                # CD to the mountpoint to be sure

                cd "$mntpoint"

                if [[ $? != 0 ]]; then
                echo "Could not cd to '$mntpoint'" >&2
                exit 1
                fi

                # CD to directory TEST which must exist (change as appropriate)

                newcd="$mntpoint/TEST"

                if [[ ! -d "$newcd" ]]; then
                echo "Directory '$newcd' not found - can't test!" >&2
                echo "...exiting" >&2
                exit 1
                fi

                cd "$newcd"

                if [[ $? != 0 ]]; then
                echo "Could not cd to '$newcd'" >&2
                exit 1
                fi

                # Create a file and check the permissions

                testfile=$(mktemp --tmpdir="$newcd")

                if [[ $? != 0 ]]; then
                echo "Could not create temporary file in '$newcd'" >&2
                exit 1
                fi

                stat=$(stat --format="group=%G user=%U access=%A" "$testfile")
                soll="group=$group user=$user access=-rw-rw----"

                if [[ $stat != "$soll" ]]; then
                echo "Incorrect permissions on temporary file '$testfile'" >&2
                echo "Expected: $soll" >&2
                echo "Obtained: $stat" >&2
                echo "...exiting" >&2
                exit 1
                fi

                /bin/rm "$testfile"

                echo "Mounted '$unc' on '$mntpoint'" >&2





                share|improve this answer































                  1














                  how the different mounting methods work has been exhausted, but there's something you might want to consider



                  if you don't want to enter your credentials directly into /etc/fstab you can use a mount option instead:
                  credentials=/your/path/here/.credentials



                  this should contain
                  username=msusername
                  password=mspassword



                  Save the file and exit your choice editor.



                  permissions should be changed to
                  chmod 600



                  if you have an encrypted home directory and want your mount to be up on boot make sure to place the file outside your home directory.
                  in /etc/ or /media/ might be a suitable and easily memorable place.






                  share|improve this answer
























                    Your Answer








                    StackExchange.ready(function() {
                    var channelOptions = {
                    tags: "".split(" "),
                    id: "89"
                    };
                    initTagRenderer("".split(" "), "".split(" "), channelOptions);

                    StackExchange.using("externalEditor", function() {
                    // Have to fire editor after snippets, if snippets enabled
                    if (StackExchange.settings.snippets.snippetsEnabled) {
                    StackExchange.using("snippets", function() {
                    createEditor();
                    });
                    }
                    else {
                    createEditor();
                    }
                    });

                    function createEditor() {
                    StackExchange.prepareEditor({
                    heartbeatType: 'answer',
                    autoActivateHeartbeat: false,
                    convertImagesToLinks: true,
                    noModals: true,
                    showLowRepImageUploadWarning: true,
                    reputationToPostImages: 10,
                    bindNavPrevention: true,
                    postfix: "",
                    imageUploader: {
                    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                    allowUrls: true
                    },
                    onDemand: true,
                    discardSelector: ".discard-answer"
                    ,immediatelyShowMarkdownHelp:true
                    });


                    }
                    });














                    draft saved

                    draft discarded


















                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f101029%2fhow-do-i-mount-a-cifs-share%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown

























                    8 Answers
                    8






                    active

                    oldest

                    votes








                    8 Answers
                    8






                    active

                    oldest

                    votes









                    active

                    oldest

                    votes






                    active

                    oldest

                    votes









                    80














                    There is pyNeighborhood which is a gui for mounting samba shares and available in the software centre for download.



                    There is a good article located here on how to set it up and use it.



                    First install cifs utils



                    sudo apt-get install cifs-utils




                    Alternatively, the basic terminal command is :



                    mount -t cifs -o username=USERNAME,password=PASSWD //192.168.1.88/shares /mnt/share


                    If you'd like to see your mount in Nautilus it would be good to create a subfolder first in /media/USERNAME/ for example:



                    mkdir /media/paul/cifsShare


                    also, password could ommited in the mount command for example (will also demonstrate file/folder modes):



                    sudo mount -t cifs //nas-server/cifsShare /media/paul/cifsShare -o username=paulOnNAS,iocharset=utf8,file_mode=0777,dir_mode=0777,soft,user,noperm


                    in this case you'll be asked for the password (actually for 2 passwords) on the mounting moment.



                    Have a read through the Samba documentation here on how to do it and set it up correctly to mount on start up etc.






                    share|improve this answer





















                    • 2





                      is there a way to mount the samba share without 1) hard coding the password and 2) having to be root?

                      – mcExchange
                      Jan 25 '16 at 14:18






                    • 1





                      @mcExchange root is needed and you can use smb credentials file to protect you credentials

                      – adampski
                      Feb 29 '16 at 13:14






                    • 4





                      also make sure you have cifs-utils installed: sudo apt-get install cifs-utils. For more info this ubuntu help doc is great.

                      – Marco Pashkov
                      Mar 31 '16 at 5:20






                    • 1





                      pyNeighborhood gives me segmentation fault when started over ssh in ubuntu 14.04

                      – Pavel Niedoba
                      May 8 '16 at 22:12






                    • 1





                      @MarcoPashkov cifs-utils is what got me up and going. None of this would work otherwise. This should be directly included in the answer.

                      – rubynorails
                      Jul 5 '16 at 19:32
















                    80














                    There is pyNeighborhood which is a gui for mounting samba shares and available in the software centre for download.



                    There is a good article located here on how to set it up and use it.



                    First install cifs utils



                    sudo apt-get install cifs-utils




                    Alternatively, the basic terminal command is :



                    mount -t cifs -o username=USERNAME,password=PASSWD //192.168.1.88/shares /mnt/share


                    If you'd like to see your mount in Nautilus it would be good to create a subfolder first in /media/USERNAME/ for example:



                    mkdir /media/paul/cifsShare


                    also, password could ommited in the mount command for example (will also demonstrate file/folder modes):



                    sudo mount -t cifs //nas-server/cifsShare /media/paul/cifsShare -o username=paulOnNAS,iocharset=utf8,file_mode=0777,dir_mode=0777,soft,user,noperm


                    in this case you'll be asked for the password (actually for 2 passwords) on the mounting moment.



                    Have a read through the Samba documentation here on how to do it and set it up correctly to mount on start up etc.






                    share|improve this answer





















                    • 2





                      is there a way to mount the samba share without 1) hard coding the password and 2) having to be root?

                      – mcExchange
                      Jan 25 '16 at 14:18






                    • 1





                      @mcExchange root is needed and you can use smb credentials file to protect you credentials

                      – adampski
                      Feb 29 '16 at 13:14






                    • 4





                      also make sure you have cifs-utils installed: sudo apt-get install cifs-utils. For more info this ubuntu help doc is great.

                      – Marco Pashkov
                      Mar 31 '16 at 5:20






                    • 1





                      pyNeighborhood gives me segmentation fault when started over ssh in ubuntu 14.04

                      – Pavel Niedoba
                      May 8 '16 at 22:12






                    • 1





                      @MarcoPashkov cifs-utils is what got me up and going. None of this would work otherwise. This should be directly included in the answer.

                      – rubynorails
                      Jul 5 '16 at 19:32














                    80












                    80








                    80







                    There is pyNeighborhood which is a gui for mounting samba shares and available in the software centre for download.



                    There is a good article located here on how to set it up and use it.



                    First install cifs utils



                    sudo apt-get install cifs-utils




                    Alternatively, the basic terminal command is :



                    mount -t cifs -o username=USERNAME,password=PASSWD //192.168.1.88/shares /mnt/share


                    If you'd like to see your mount in Nautilus it would be good to create a subfolder first in /media/USERNAME/ for example:



                    mkdir /media/paul/cifsShare


                    also, password could ommited in the mount command for example (will also demonstrate file/folder modes):



                    sudo mount -t cifs //nas-server/cifsShare /media/paul/cifsShare -o username=paulOnNAS,iocharset=utf8,file_mode=0777,dir_mode=0777,soft,user,noperm


                    in this case you'll be asked for the password (actually for 2 passwords) on the mounting moment.



                    Have a read through the Samba documentation here on how to do it and set it up correctly to mount on start up etc.






                    share|improve this answer















                    There is pyNeighborhood which is a gui for mounting samba shares and available in the software centre for download.



                    There is a good article located here on how to set it up and use it.



                    First install cifs utils



                    sudo apt-get install cifs-utils




                    Alternatively, the basic terminal command is :



                    mount -t cifs -o username=USERNAME,password=PASSWD //192.168.1.88/shares /mnt/share


                    If you'd like to see your mount in Nautilus it would be good to create a subfolder first in /media/USERNAME/ for example:



                    mkdir /media/paul/cifsShare


                    also, password could ommited in the mount command for example (will also demonstrate file/folder modes):



                    sudo mount -t cifs //nas-server/cifsShare /media/paul/cifsShare -o username=paulOnNAS,iocharset=utf8,file_mode=0777,dir_mode=0777,soft,user,noperm


                    in this case you'll be asked for the password (actually for 2 passwords) on the mounting moment.



                    Have a read through the Samba documentation here on how to do it and set it up correctly to mount on start up etc.







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Aug 8 '17 at 22:46









                    Oleg Kokorin

                    1264




                    1264










                    answered Feb 3 '12 at 7:33









                    map7map7

                    846513




                    846513








                    • 2





                      is there a way to mount the samba share without 1) hard coding the password and 2) having to be root?

                      – mcExchange
                      Jan 25 '16 at 14:18






                    • 1





                      @mcExchange root is needed and you can use smb credentials file to protect you credentials

                      – adampski
                      Feb 29 '16 at 13:14






                    • 4





                      also make sure you have cifs-utils installed: sudo apt-get install cifs-utils. For more info this ubuntu help doc is great.

                      – Marco Pashkov
                      Mar 31 '16 at 5:20






                    • 1





                      pyNeighborhood gives me segmentation fault when started over ssh in ubuntu 14.04

                      – Pavel Niedoba
                      May 8 '16 at 22:12






                    • 1





                      @MarcoPashkov cifs-utils is what got me up and going. None of this would work otherwise. This should be directly included in the answer.

                      – rubynorails
                      Jul 5 '16 at 19:32














                    • 2





                      is there a way to mount the samba share without 1) hard coding the password and 2) having to be root?

                      – mcExchange
                      Jan 25 '16 at 14:18






                    • 1





                      @mcExchange root is needed and you can use smb credentials file to protect you credentials

                      – adampski
                      Feb 29 '16 at 13:14






                    • 4





                      also make sure you have cifs-utils installed: sudo apt-get install cifs-utils. For more info this ubuntu help doc is great.

                      – Marco Pashkov
                      Mar 31 '16 at 5:20






                    • 1





                      pyNeighborhood gives me segmentation fault when started over ssh in ubuntu 14.04

                      – Pavel Niedoba
                      May 8 '16 at 22:12






                    • 1





                      @MarcoPashkov cifs-utils is what got me up and going. None of this would work otherwise. This should be directly included in the answer.

                      – rubynorails
                      Jul 5 '16 at 19:32








                    2




                    2





                    is there a way to mount the samba share without 1) hard coding the password and 2) having to be root?

                    – mcExchange
                    Jan 25 '16 at 14:18





                    is there a way to mount the samba share without 1) hard coding the password and 2) having to be root?

                    – mcExchange
                    Jan 25 '16 at 14:18




                    1




                    1





                    @mcExchange root is needed and you can use smb credentials file to protect you credentials

                    – adampski
                    Feb 29 '16 at 13:14





                    @mcExchange root is needed and you can use smb credentials file to protect you credentials

                    – adampski
                    Feb 29 '16 at 13:14




                    4




                    4





                    also make sure you have cifs-utils installed: sudo apt-get install cifs-utils. For more info this ubuntu help doc is great.

                    – Marco Pashkov
                    Mar 31 '16 at 5:20





                    also make sure you have cifs-utils installed: sudo apt-get install cifs-utils. For more info this ubuntu help doc is great.

                    – Marco Pashkov
                    Mar 31 '16 at 5:20




                    1




                    1





                    pyNeighborhood gives me segmentation fault when started over ssh in ubuntu 14.04

                    – Pavel Niedoba
                    May 8 '16 at 22:12





                    pyNeighborhood gives me segmentation fault when started over ssh in ubuntu 14.04

                    – Pavel Niedoba
                    May 8 '16 at 22:12




                    1




                    1





                    @MarcoPashkov cifs-utils is what got me up and going. None of this would work otherwise. This should be directly included in the answer.

                    – rubynorails
                    Jul 5 '16 at 19:32





                    @MarcoPashkov cifs-utils is what got me up and going. None of this would work otherwise. This should be directly included in the answer.

                    – rubynorails
                    Jul 5 '16 at 19:32













                    12














                    It's as map7 said, but if you don't want to use root permissions every time you change a file on the drive, then you'll have to mount to a user folder, and make sure the gid and uid are set to your username.



                    The command setting them:



                    mount -t cifs -o username=USERNAME,password=PASSWD,uid=$USER,gid=$USER //192.168.1.88/shares ~/mnt/share


                    Note that mnt folder was created in ~/mnt/share instead of /mnt/share.



                    Also you can leave out password=PASSWD if you want it to prompt you instead of you having it in the command, which is potentially stored in your shell's history:



                    mount -t cifs -o username=USERNAME,uid=$USER,gid=$USER //192.168.1.88/shares ~/mnt/share





                    share|improve this answer





















                    • 1





                      Make a more complete answer, with some examples and I'll upvote :)

                      – storm
                      Dec 21 '16 at 15:02
















                    12














                    It's as map7 said, but if you don't want to use root permissions every time you change a file on the drive, then you'll have to mount to a user folder, and make sure the gid and uid are set to your username.



                    The command setting them:



                    mount -t cifs -o username=USERNAME,password=PASSWD,uid=$USER,gid=$USER //192.168.1.88/shares ~/mnt/share


                    Note that mnt folder was created in ~/mnt/share instead of /mnt/share.



                    Also you can leave out password=PASSWD if you want it to prompt you instead of you having it in the command, which is potentially stored in your shell's history:



                    mount -t cifs -o username=USERNAME,uid=$USER,gid=$USER //192.168.1.88/shares ~/mnt/share





                    share|improve this answer





















                    • 1





                      Make a more complete answer, with some examples and I'll upvote :)

                      – storm
                      Dec 21 '16 at 15:02














                    12












                    12








                    12







                    It's as map7 said, but if you don't want to use root permissions every time you change a file on the drive, then you'll have to mount to a user folder, and make sure the gid and uid are set to your username.



                    The command setting them:



                    mount -t cifs -o username=USERNAME,password=PASSWD,uid=$USER,gid=$USER //192.168.1.88/shares ~/mnt/share


                    Note that mnt folder was created in ~/mnt/share instead of /mnt/share.



                    Also you can leave out password=PASSWD if you want it to prompt you instead of you having it in the command, which is potentially stored in your shell's history:



                    mount -t cifs -o username=USERNAME,uid=$USER,gid=$USER //192.168.1.88/shares ~/mnt/share





                    share|improve this answer















                    It's as map7 said, but if you don't want to use root permissions every time you change a file on the drive, then you'll have to mount to a user folder, and make sure the gid and uid are set to your username.



                    The command setting them:



                    mount -t cifs -o username=USERNAME,password=PASSWD,uid=$USER,gid=$USER //192.168.1.88/shares ~/mnt/share


                    Note that mnt folder was created in ~/mnt/share instead of /mnt/share.



                    Also you can leave out password=PASSWD if you want it to prompt you instead of you having it in the command, which is potentially stored in your shell's history:



                    mount -t cifs -o username=USERNAME,uid=$USER,gid=$USER //192.168.1.88/shares ~/mnt/share






                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited May 29 '17 at 11:12









                    Huge

                    407616




                    407616










                    answered Dec 21 '16 at 14:37









                    binamenatorbinamenator

                    14315




                    14315








                    • 1





                      Make a more complete answer, with some examples and I'll upvote :)

                      – storm
                      Dec 21 '16 at 15:02














                    • 1





                      Make a more complete answer, with some examples and I'll upvote :)

                      – storm
                      Dec 21 '16 at 15:02








                    1




                    1





                    Make a more complete answer, with some examples and I'll upvote :)

                    – storm
                    Dec 21 '16 at 15:02





                    Make a more complete answer, with some examples and I'll upvote :)

                    – storm
                    Dec 21 '16 at 15:02











                    5














                    1) My samba share shows in Caja (the ubuntu 16.04 „explorer“) as



                    smb://thinkpad/ddrive/


                    This is a good lithmus test, there are no connection/path issues.



                    (caveat: If you get asked by caja about password credentials from your windows machine, you might want to switch Domain from WORKGROUP to the name of the machine, i.e. ‘thinkpad’. Then the truly local login credentials of your drive should do.)



                    2) If that works, here comes the command:



                    sudo mount -t cifs -o username=frank //thinkpad/ddrive /mnt/ddrive



                    • Make sure beforehand, /mnt/ddrive exists as an empty directory.

                    • You cold also add a ,password=supersecret directly (no space) after username=, but you can also wait for being prompted, when you enter the command.






                    share|improve this answer



















                    • 2





                      It took me a bit to figure out, where I can type in the smb://.... path in Nemo / Linux Mint 18, but actually it's quite simple: if the path input box is not visible, enable it in the View menu.

                      – Pedi T.
                      Aug 10 '17 at 16:32
















                    5














                    1) My samba share shows in Caja (the ubuntu 16.04 „explorer“) as



                    smb://thinkpad/ddrive/


                    This is a good lithmus test, there are no connection/path issues.



                    (caveat: If you get asked by caja about password credentials from your windows machine, you might want to switch Domain from WORKGROUP to the name of the machine, i.e. ‘thinkpad’. Then the truly local login credentials of your drive should do.)



                    2) If that works, here comes the command:



                    sudo mount -t cifs -o username=frank //thinkpad/ddrive /mnt/ddrive



                    • Make sure beforehand, /mnt/ddrive exists as an empty directory.

                    • You cold also add a ,password=supersecret directly (no space) after username=, but you can also wait for being prompted, when you enter the command.






                    share|improve this answer



















                    • 2





                      It took me a bit to figure out, where I can type in the smb://.... path in Nemo / Linux Mint 18, but actually it's quite simple: if the path input box is not visible, enable it in the View menu.

                      – Pedi T.
                      Aug 10 '17 at 16:32














                    5












                    5








                    5







                    1) My samba share shows in Caja (the ubuntu 16.04 „explorer“) as



                    smb://thinkpad/ddrive/


                    This is a good lithmus test, there are no connection/path issues.



                    (caveat: If you get asked by caja about password credentials from your windows machine, you might want to switch Domain from WORKGROUP to the name of the machine, i.e. ‘thinkpad’. Then the truly local login credentials of your drive should do.)



                    2) If that works, here comes the command:



                    sudo mount -t cifs -o username=frank //thinkpad/ddrive /mnt/ddrive



                    • Make sure beforehand, /mnt/ddrive exists as an empty directory.

                    • You cold also add a ,password=supersecret directly (no space) after username=, but you can also wait for being prompted, when you enter the command.






                    share|improve this answer













                    1) My samba share shows in Caja (the ubuntu 16.04 „explorer“) as



                    smb://thinkpad/ddrive/


                    This is a good lithmus test, there are no connection/path issues.



                    (caveat: If you get asked by caja about password credentials from your windows machine, you might want to switch Domain from WORKGROUP to the name of the machine, i.e. ‘thinkpad’. Then the truly local login credentials of your drive should do.)



                    2) If that works, here comes the command:



                    sudo mount -t cifs -o username=frank //thinkpad/ddrive /mnt/ddrive



                    • Make sure beforehand, /mnt/ddrive exists as an empty directory.

                    • You cold also add a ,password=supersecret directly (no space) after username=, but you can also wait for being prompted, when you enter the command.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Nov 10 '16 at 15:50









                    Frank NockeFrank Nocke

                    498421




                    498421








                    • 2





                      It took me a bit to figure out, where I can type in the smb://.... path in Nemo / Linux Mint 18, but actually it's quite simple: if the path input box is not visible, enable it in the View menu.

                      – Pedi T.
                      Aug 10 '17 at 16:32














                    • 2





                      It took me a bit to figure out, where I can type in the smb://.... path in Nemo / Linux Mint 18, but actually it's quite simple: if the path input box is not visible, enable it in the View menu.

                      – Pedi T.
                      Aug 10 '17 at 16:32








                    2




                    2





                    It took me a bit to figure out, where I can type in the smb://.... path in Nemo / Linux Mint 18, but actually it's quite simple: if the path input box is not visible, enable it in the View menu.

                    – Pedi T.
                    Aug 10 '17 at 16:32





                    It took me a bit to figure out, where I can type in the smb://.... path in Nemo / Linux Mint 18, but actually it's quite simple: if the path input box is not visible, enable it in the View menu.

                    – Pedi T.
                    Aug 10 '17 at 16:32











                    3














                    I disagree with the claim that root is always necessary to make cifs connections go. It is true, it is always needed for CLI smbmount, but a file manager such as nautilus has ability to mount a cifs share and it is not necessary to be root.



                    I don't use Gnome, but I still have Nautilus installed. Run this in a terminal to prevent having it try to take over the desktop



                    $ nautilus --no-desktop &


                    In Ubuntu 16.04, left side tree menu has "Connect to Server" on the bottom. Click that, the suggestion is type "smb://foo.example.com". smb is old word for "cifs", and if you put in your server and share with smb:// at beginning, connection does work! I promise. If your share is a named thing, it is required after a slash, "smb://foo.example.com/myshare".



                    I've used other file managers in same way. Protocol has to be "smb://".






                    share|improve this answer




























                      3














                      I disagree with the claim that root is always necessary to make cifs connections go. It is true, it is always needed for CLI smbmount, but a file manager such as nautilus has ability to mount a cifs share and it is not necessary to be root.



                      I don't use Gnome, but I still have Nautilus installed. Run this in a terminal to prevent having it try to take over the desktop



                      $ nautilus --no-desktop &


                      In Ubuntu 16.04, left side tree menu has "Connect to Server" on the bottom. Click that, the suggestion is type "smb://foo.example.com". smb is old word for "cifs", and if you put in your server and share with smb:// at beginning, connection does work! I promise. If your share is a named thing, it is required after a slash, "smb://foo.example.com/myshare".



                      I've used other file managers in same way. Protocol has to be "smb://".






                      share|improve this answer


























                        3












                        3








                        3







                        I disagree with the claim that root is always necessary to make cifs connections go. It is true, it is always needed for CLI smbmount, but a file manager such as nautilus has ability to mount a cifs share and it is not necessary to be root.



                        I don't use Gnome, but I still have Nautilus installed. Run this in a terminal to prevent having it try to take over the desktop



                        $ nautilus --no-desktop &


                        In Ubuntu 16.04, left side tree menu has "Connect to Server" on the bottom. Click that, the suggestion is type "smb://foo.example.com". smb is old word for "cifs", and if you put in your server and share with smb:// at beginning, connection does work! I promise. If your share is a named thing, it is required after a slash, "smb://foo.example.com/myshare".



                        I've used other file managers in same way. Protocol has to be "smb://".






                        share|improve this answer













                        I disagree with the claim that root is always necessary to make cifs connections go. It is true, it is always needed for CLI smbmount, but a file manager such as nautilus has ability to mount a cifs share and it is not necessary to be root.



                        I don't use Gnome, but I still have Nautilus installed. Run this in a terminal to prevent having it try to take over the desktop



                        $ nautilus --no-desktop &


                        In Ubuntu 16.04, left side tree menu has "Connect to Server" on the bottom. Click that, the suggestion is type "smb://foo.example.com". smb is old word for "cifs", and if you put in your server and share with smb:// at beginning, connection does work! I promise. If your share is a named thing, it is required after a slash, "smb://foo.example.com/myshare".



                        I've used other file managers in same way. Protocol has to be "smb://".







                        share|improve this answer












                        share|improve this answer



                        share|improve this answer










                        answered Jul 15 '16 at 2:59









                        pauljohn32pauljohn32

                        2,4691026




                        2,4691026























                            3
















                            1. You can put all those details in /etc/fstab so you can have directories mounted on system startup. If windows or SMB server is on IP address 192.168.1.1



                              /etc/fstab
                              //192.168.1.1/SharedFolder/ /mnt/linux_smb cifs username=winuser,password=TopSecret 0 0



                            2. Create directory as linux mount point



                              mkdir /mnt/linux_smb
                              chmod 755 /mnt/linux_smb



                            3. For the first time mount this manually



                              mount -a



                            4. Eventual errors can be found by



                              dmesg | tail 







                            share|improve this answer




























                              3
















                              1. You can put all those details in /etc/fstab so you can have directories mounted on system startup. If windows or SMB server is on IP address 192.168.1.1



                                /etc/fstab
                                //192.168.1.1/SharedFolder/ /mnt/linux_smb cifs username=winuser,password=TopSecret 0 0



                              2. Create directory as linux mount point



                                mkdir /mnt/linux_smb
                                chmod 755 /mnt/linux_smb



                              3. For the first time mount this manually



                                mount -a



                              4. Eventual errors can be found by



                                dmesg | tail 







                              share|improve this answer


























                                3












                                3








                                3









                                1. You can put all those details in /etc/fstab so you can have directories mounted on system startup. If windows or SMB server is on IP address 192.168.1.1



                                  /etc/fstab
                                  //192.168.1.1/SharedFolder/ /mnt/linux_smb cifs username=winuser,password=TopSecret 0 0



                                2. Create directory as linux mount point



                                  mkdir /mnt/linux_smb
                                  chmod 755 /mnt/linux_smb



                                3. For the first time mount this manually



                                  mount -a



                                4. Eventual errors can be found by



                                  dmesg | tail 







                                share|improve this answer















                                1. You can put all those details in /etc/fstab so you can have directories mounted on system startup. If windows or SMB server is on IP address 192.168.1.1



                                  /etc/fstab
                                  //192.168.1.1/SharedFolder/ /mnt/linux_smb cifs username=winuser,password=TopSecret 0 0



                                2. Create directory as linux mount point



                                  mkdir /mnt/linux_smb
                                  chmod 755 /mnt/linux_smb



                                3. For the first time mount this manually



                                  mount -a



                                4. Eventual errors can be found by



                                  dmesg | tail 








                                share|improve this answer












                                share|improve this answer



                                share|improve this answer










                                answered Sep 15 '17 at 12:36









                                Amit VujicAmit Vujic

                                16027




                                16027























                                    3
















                                    1. There is specific issue possible and very frustrating to resolve when versions of CIF/SMB are not compatible between Linux and Windows.
                                      In that case you can just make minor chnage in fstab line adding "vers=2.1"



                                      So, if Windows or SMB server is on IP address 192.168.1.1



                                      /etc/fstab

                                      //192.168.1.1/SharedFolder/ /mnt/linux_smb cifs vers=2.1,username=winuser,password=TopSecret 0 0


                                    2. Steps 2, 3 and 4 remains the same as in previous answer.







                                    share|improve this answer




























                                      3
















                                      1. There is specific issue possible and very frustrating to resolve when versions of CIF/SMB are not compatible between Linux and Windows.
                                        In that case you can just make minor chnage in fstab line adding "vers=2.1"



                                        So, if Windows or SMB server is on IP address 192.168.1.1



                                        /etc/fstab

                                        //192.168.1.1/SharedFolder/ /mnt/linux_smb cifs vers=2.1,username=winuser,password=TopSecret 0 0


                                      2. Steps 2, 3 and 4 remains the same as in previous answer.







                                      share|improve this answer


























                                        3












                                        3








                                        3









                                        1. There is specific issue possible and very frustrating to resolve when versions of CIF/SMB are not compatible between Linux and Windows.
                                          In that case you can just make minor chnage in fstab line adding "vers=2.1"



                                          So, if Windows or SMB server is on IP address 192.168.1.1



                                          /etc/fstab

                                          //192.168.1.1/SharedFolder/ /mnt/linux_smb cifs vers=2.1,username=winuser,password=TopSecret 0 0


                                        2. Steps 2, 3 and 4 remains the same as in previous answer.







                                        share|improve this answer















                                        1. There is specific issue possible and very frustrating to resolve when versions of CIF/SMB are not compatible between Linux and Windows.
                                          In that case you can just make minor chnage in fstab line adding "vers=2.1"



                                          So, if Windows or SMB server is on IP address 192.168.1.1



                                          /etc/fstab

                                          //192.168.1.1/SharedFolder/ /mnt/linux_smb cifs vers=2.1,username=winuser,password=TopSecret 0 0


                                        2. Steps 2, 3 and 4 remains the same as in previous answer.








                                        share|improve this answer












                                        share|improve this answer



                                        share|improve this answer










                                        answered Nov 1 '17 at 12:30









                                        Amit VujicAmit Vujic

                                        16027




                                        16027























                                            1














                                            I put together a little script (it's meant for Fedora though) to mount the CIFS filesystem from the command line and create/delete a test file. May be of some use:



                                            #!/bin/bash
                                            # Passes https://www.shellcheck.net/

                                            set -o nounset

                                            # See
                                            # https://wiki.samba.org/index.php/Mounting_samba_shares_from_a_unix_client
                                            # https://access.redhat.com/solutions/448263
                                            # and also
                                            # https://serverfault.com/questions/309429/mount-cifs-credentials-file-has-special-character

                                            # One needs to run "yum install cifs-utils" to have the kernel module, man page
                                            # and other stuff.

                                            rpm --query cifs-utils > /dev/null

                                            if [[ $? != 0 ]]; then
                                            echo "Package cifs-utils is not installed -- exiting" >&2
                                            exit 1
                                            else
                                            ver=$(rpm --query cifs-utils)
                                            echo "Package $ver exists ... good!" >&2
                                            fi

                                            # Where to find credentials? Use the "credential file" approach, which
                                            # we call "authfile". Example content (w/o the leading #) below.
                                            # Make sure there are no spaces around '=' (this is different than
                                            # for "smbclient" which can deal with spaces around '='.)
                                            # ----8<------8<----------------
                                            # username=prisoner
                                            # password=KAR120C
                                            # domain=VILLAGE
                                            # ----8<------8<----------------
                                            # Trailing empty lines will lead to (harmless) error messages
                                            # "Credential formatted incorrectly: (null)"

                                            authfile='/etc/smb.passwd' # Make sure read permissions are restricted!!

                                            # Server to contact.
                                            # In the UNC path, we will use DNS name instead of the (more correct?)
                                            # NetBIOS name.
                                            # mount.cifs manpage says: "To mount using the cifs client, a tcp name
                                            # (rather than netbios name) must be specified for the server."

                                            server_dns=thedome.example.com

                                            # The name of the connecting client, just to be sure (probably useless)

                                            client_nbs=$(hostname --short | tr '[:lower:]' '[:upper]')

                                            if [[ -z $client_nbs ]]; then
                                            client_nbs=UNKNOWN
                                            fi

                                            # Connect to a certain service (which is a fileservice)
                                            # and then switch to the given directory.
                                            # Instead of appending $directory to form the complete UNC
                                            # (Uniform Naming Convention) path, one could also use the option
                                            # "prefixpath".
                                            # If there is no need to mount a subdirectory of the service,
                                            # the UNC would just be unc="//$server_dns/$service_name"

                                            service_name='information'
                                            directory='PERSONALDATA'

                                            unc="//$server_dns/$service_name/$directory"

                                            # Finally, we will mount the CIFS filesystem here (the
                                            # permissions on that node are not directly of interest)

                                            mntpoint=/mnt/portal

                                            if [[ ! -d "$mntpoint" ]]; then
                                            mkdir "$mntpoint"
                                            if [[ $? != 0 ]]; then
                                            echo "Could not create mountpoint '$mntpoint' -- exiting" >&2
                                            exit 1
                                            fi
                                            fi

                                            # Only this user will be able to access the mounted CIFS filesystem

                                            user=number6
                                            group=number6

                                            # Try to mount this so that only user "number6" can access it

                                            mount -t cifs
                                            "$unc"
                                            "$mntpoint"
                                            --read-write
                                            --verbose
                                            -o "credentials=$authfile,uid=$user,gid=$group,netbiosname=$client_nbs,file_mode=0660,dir_mode=0770"

                                            res=$?

                                            if [[ $res != 0 ]]; then
                                            echo "Mount failed!" >&2
                                            echo "Return code $res; more info may be in kernel log or daemon log" >&2
                                            echo "Try 'journalctl SYSLOG_FACILITY=0' or 'journalctl SYSLOG_FACILITY=3'" >&2
                                            echo "...exiting" >&2
                                            exit 1
                                            fi

                                            # Check permissions on the mount point

                                            stat=$(stat --format="group=%G user=%U access=%A" "$mntpoint")
                                            soll="group=$group user=$user access=drwxrwx---"

                                            if [[ $stat != "$soll" ]]; then
                                            echo "Incorrect permissions on root of '$mntpoint'" >&2
                                            echo "Expected: $soll" >&2
                                            echo "Obtained: $stat" >&2
                                            echo "...exiting" >&2
                                            umount "$mntpoint"
                                            exit 1
                                            fi

                                            # CD to the mountpoint to be sure

                                            cd "$mntpoint"

                                            if [[ $? != 0 ]]; then
                                            echo "Could not cd to '$mntpoint'" >&2
                                            exit 1
                                            fi

                                            # CD to directory TEST which must exist (change as appropriate)

                                            newcd="$mntpoint/TEST"

                                            if [[ ! -d "$newcd" ]]; then
                                            echo "Directory '$newcd' not found - can't test!" >&2
                                            echo "...exiting" >&2
                                            exit 1
                                            fi

                                            cd "$newcd"

                                            if [[ $? != 0 ]]; then
                                            echo "Could not cd to '$newcd'" >&2
                                            exit 1
                                            fi

                                            # Create a file and check the permissions

                                            testfile=$(mktemp --tmpdir="$newcd")

                                            if [[ $? != 0 ]]; then
                                            echo "Could not create temporary file in '$newcd'" >&2
                                            exit 1
                                            fi

                                            stat=$(stat --format="group=%G user=%U access=%A" "$testfile")
                                            soll="group=$group user=$user access=-rw-rw----"

                                            if [[ $stat != "$soll" ]]; then
                                            echo "Incorrect permissions on temporary file '$testfile'" >&2
                                            echo "Expected: $soll" >&2
                                            echo "Obtained: $stat" >&2
                                            echo "...exiting" >&2
                                            exit 1
                                            fi

                                            /bin/rm "$testfile"

                                            echo "Mounted '$unc' on '$mntpoint'" >&2





                                            share|improve this answer




























                                              1














                                              I put together a little script (it's meant for Fedora though) to mount the CIFS filesystem from the command line and create/delete a test file. May be of some use:



                                              #!/bin/bash
                                              # Passes https://www.shellcheck.net/

                                              set -o nounset

                                              # See
                                              # https://wiki.samba.org/index.php/Mounting_samba_shares_from_a_unix_client
                                              # https://access.redhat.com/solutions/448263
                                              # and also
                                              # https://serverfault.com/questions/309429/mount-cifs-credentials-file-has-special-character

                                              # One needs to run "yum install cifs-utils" to have the kernel module, man page
                                              # and other stuff.

                                              rpm --query cifs-utils > /dev/null

                                              if [[ $? != 0 ]]; then
                                              echo "Package cifs-utils is not installed -- exiting" >&2
                                              exit 1
                                              else
                                              ver=$(rpm --query cifs-utils)
                                              echo "Package $ver exists ... good!" >&2
                                              fi

                                              # Where to find credentials? Use the "credential file" approach, which
                                              # we call "authfile". Example content (w/o the leading #) below.
                                              # Make sure there are no spaces around '=' (this is different than
                                              # for "smbclient" which can deal with spaces around '='.)
                                              # ----8<------8<----------------
                                              # username=prisoner
                                              # password=KAR120C
                                              # domain=VILLAGE
                                              # ----8<------8<----------------
                                              # Trailing empty lines will lead to (harmless) error messages
                                              # "Credential formatted incorrectly: (null)"

                                              authfile='/etc/smb.passwd' # Make sure read permissions are restricted!!

                                              # Server to contact.
                                              # In the UNC path, we will use DNS name instead of the (more correct?)
                                              # NetBIOS name.
                                              # mount.cifs manpage says: "To mount using the cifs client, a tcp name
                                              # (rather than netbios name) must be specified for the server."

                                              server_dns=thedome.example.com

                                              # The name of the connecting client, just to be sure (probably useless)

                                              client_nbs=$(hostname --short | tr '[:lower:]' '[:upper]')

                                              if [[ -z $client_nbs ]]; then
                                              client_nbs=UNKNOWN
                                              fi

                                              # Connect to a certain service (which is a fileservice)
                                              # and then switch to the given directory.
                                              # Instead of appending $directory to form the complete UNC
                                              # (Uniform Naming Convention) path, one could also use the option
                                              # "prefixpath".
                                              # If there is no need to mount a subdirectory of the service,
                                              # the UNC would just be unc="//$server_dns/$service_name"

                                              service_name='information'
                                              directory='PERSONALDATA'

                                              unc="//$server_dns/$service_name/$directory"

                                              # Finally, we will mount the CIFS filesystem here (the
                                              # permissions on that node are not directly of interest)

                                              mntpoint=/mnt/portal

                                              if [[ ! -d "$mntpoint" ]]; then
                                              mkdir "$mntpoint"
                                              if [[ $? != 0 ]]; then
                                              echo "Could not create mountpoint '$mntpoint' -- exiting" >&2
                                              exit 1
                                              fi
                                              fi

                                              # Only this user will be able to access the mounted CIFS filesystem

                                              user=number6
                                              group=number6

                                              # Try to mount this so that only user "number6" can access it

                                              mount -t cifs
                                              "$unc"
                                              "$mntpoint"
                                              --read-write
                                              --verbose
                                              -o "credentials=$authfile,uid=$user,gid=$group,netbiosname=$client_nbs,file_mode=0660,dir_mode=0770"

                                              res=$?

                                              if [[ $res != 0 ]]; then
                                              echo "Mount failed!" >&2
                                              echo "Return code $res; more info may be in kernel log or daemon log" >&2
                                              echo "Try 'journalctl SYSLOG_FACILITY=0' or 'journalctl SYSLOG_FACILITY=3'" >&2
                                              echo "...exiting" >&2
                                              exit 1
                                              fi

                                              # Check permissions on the mount point

                                              stat=$(stat --format="group=%G user=%U access=%A" "$mntpoint")
                                              soll="group=$group user=$user access=drwxrwx---"

                                              if [[ $stat != "$soll" ]]; then
                                              echo "Incorrect permissions on root of '$mntpoint'" >&2
                                              echo "Expected: $soll" >&2
                                              echo "Obtained: $stat" >&2
                                              echo "...exiting" >&2
                                              umount "$mntpoint"
                                              exit 1
                                              fi

                                              # CD to the mountpoint to be sure

                                              cd "$mntpoint"

                                              if [[ $? != 0 ]]; then
                                              echo "Could not cd to '$mntpoint'" >&2
                                              exit 1
                                              fi

                                              # CD to directory TEST which must exist (change as appropriate)

                                              newcd="$mntpoint/TEST"

                                              if [[ ! -d "$newcd" ]]; then
                                              echo "Directory '$newcd' not found - can't test!" >&2
                                              echo "...exiting" >&2
                                              exit 1
                                              fi

                                              cd "$newcd"

                                              if [[ $? != 0 ]]; then
                                              echo "Could not cd to '$newcd'" >&2
                                              exit 1
                                              fi

                                              # Create a file and check the permissions

                                              testfile=$(mktemp --tmpdir="$newcd")

                                              if [[ $? != 0 ]]; then
                                              echo "Could not create temporary file in '$newcd'" >&2
                                              exit 1
                                              fi

                                              stat=$(stat --format="group=%G user=%U access=%A" "$testfile")
                                              soll="group=$group user=$user access=-rw-rw----"

                                              if [[ $stat != "$soll" ]]; then
                                              echo "Incorrect permissions on temporary file '$testfile'" >&2
                                              echo "Expected: $soll" >&2
                                              echo "Obtained: $stat" >&2
                                              echo "...exiting" >&2
                                              exit 1
                                              fi

                                              /bin/rm "$testfile"

                                              echo "Mounted '$unc' on '$mntpoint'" >&2





                                              share|improve this answer


























                                                1












                                                1








                                                1







                                                I put together a little script (it's meant for Fedora though) to mount the CIFS filesystem from the command line and create/delete a test file. May be of some use:



                                                #!/bin/bash
                                                # Passes https://www.shellcheck.net/

                                                set -o nounset

                                                # See
                                                # https://wiki.samba.org/index.php/Mounting_samba_shares_from_a_unix_client
                                                # https://access.redhat.com/solutions/448263
                                                # and also
                                                # https://serverfault.com/questions/309429/mount-cifs-credentials-file-has-special-character

                                                # One needs to run "yum install cifs-utils" to have the kernel module, man page
                                                # and other stuff.

                                                rpm --query cifs-utils > /dev/null

                                                if [[ $? != 0 ]]; then
                                                echo "Package cifs-utils is not installed -- exiting" >&2
                                                exit 1
                                                else
                                                ver=$(rpm --query cifs-utils)
                                                echo "Package $ver exists ... good!" >&2
                                                fi

                                                # Where to find credentials? Use the "credential file" approach, which
                                                # we call "authfile". Example content (w/o the leading #) below.
                                                # Make sure there are no spaces around '=' (this is different than
                                                # for "smbclient" which can deal with spaces around '='.)
                                                # ----8<------8<----------------
                                                # username=prisoner
                                                # password=KAR120C
                                                # domain=VILLAGE
                                                # ----8<------8<----------------
                                                # Trailing empty lines will lead to (harmless) error messages
                                                # "Credential formatted incorrectly: (null)"

                                                authfile='/etc/smb.passwd' # Make sure read permissions are restricted!!

                                                # Server to contact.
                                                # In the UNC path, we will use DNS name instead of the (more correct?)
                                                # NetBIOS name.
                                                # mount.cifs manpage says: "To mount using the cifs client, a tcp name
                                                # (rather than netbios name) must be specified for the server."

                                                server_dns=thedome.example.com

                                                # The name of the connecting client, just to be sure (probably useless)

                                                client_nbs=$(hostname --short | tr '[:lower:]' '[:upper]')

                                                if [[ -z $client_nbs ]]; then
                                                client_nbs=UNKNOWN
                                                fi

                                                # Connect to a certain service (which is a fileservice)
                                                # and then switch to the given directory.
                                                # Instead of appending $directory to form the complete UNC
                                                # (Uniform Naming Convention) path, one could also use the option
                                                # "prefixpath".
                                                # If there is no need to mount a subdirectory of the service,
                                                # the UNC would just be unc="//$server_dns/$service_name"

                                                service_name='information'
                                                directory='PERSONALDATA'

                                                unc="//$server_dns/$service_name/$directory"

                                                # Finally, we will mount the CIFS filesystem here (the
                                                # permissions on that node are not directly of interest)

                                                mntpoint=/mnt/portal

                                                if [[ ! -d "$mntpoint" ]]; then
                                                mkdir "$mntpoint"
                                                if [[ $? != 0 ]]; then
                                                echo "Could not create mountpoint '$mntpoint' -- exiting" >&2
                                                exit 1
                                                fi
                                                fi

                                                # Only this user will be able to access the mounted CIFS filesystem

                                                user=number6
                                                group=number6

                                                # Try to mount this so that only user "number6" can access it

                                                mount -t cifs
                                                "$unc"
                                                "$mntpoint"
                                                --read-write
                                                --verbose
                                                -o "credentials=$authfile,uid=$user,gid=$group,netbiosname=$client_nbs,file_mode=0660,dir_mode=0770"

                                                res=$?

                                                if [[ $res != 0 ]]; then
                                                echo "Mount failed!" >&2
                                                echo "Return code $res; more info may be in kernel log or daemon log" >&2
                                                echo "Try 'journalctl SYSLOG_FACILITY=0' or 'journalctl SYSLOG_FACILITY=3'" >&2
                                                echo "...exiting" >&2
                                                exit 1
                                                fi

                                                # Check permissions on the mount point

                                                stat=$(stat --format="group=%G user=%U access=%A" "$mntpoint")
                                                soll="group=$group user=$user access=drwxrwx---"

                                                if [[ $stat != "$soll" ]]; then
                                                echo "Incorrect permissions on root of '$mntpoint'" >&2
                                                echo "Expected: $soll" >&2
                                                echo "Obtained: $stat" >&2
                                                echo "...exiting" >&2
                                                umount "$mntpoint"
                                                exit 1
                                                fi

                                                # CD to the mountpoint to be sure

                                                cd "$mntpoint"

                                                if [[ $? != 0 ]]; then
                                                echo "Could not cd to '$mntpoint'" >&2
                                                exit 1
                                                fi

                                                # CD to directory TEST which must exist (change as appropriate)

                                                newcd="$mntpoint/TEST"

                                                if [[ ! -d "$newcd" ]]; then
                                                echo "Directory '$newcd' not found - can't test!" >&2
                                                echo "...exiting" >&2
                                                exit 1
                                                fi

                                                cd "$newcd"

                                                if [[ $? != 0 ]]; then
                                                echo "Could not cd to '$newcd'" >&2
                                                exit 1
                                                fi

                                                # Create a file and check the permissions

                                                testfile=$(mktemp --tmpdir="$newcd")

                                                if [[ $? != 0 ]]; then
                                                echo "Could not create temporary file in '$newcd'" >&2
                                                exit 1
                                                fi

                                                stat=$(stat --format="group=%G user=%U access=%A" "$testfile")
                                                soll="group=$group user=$user access=-rw-rw----"

                                                if [[ $stat != "$soll" ]]; then
                                                echo "Incorrect permissions on temporary file '$testfile'" >&2
                                                echo "Expected: $soll" >&2
                                                echo "Obtained: $stat" >&2
                                                echo "...exiting" >&2
                                                exit 1
                                                fi

                                                /bin/rm "$testfile"

                                                echo "Mounted '$unc' on '$mntpoint'" >&2





                                                share|improve this answer













                                                I put together a little script (it's meant for Fedora though) to mount the CIFS filesystem from the command line and create/delete a test file. May be of some use:



                                                #!/bin/bash
                                                # Passes https://www.shellcheck.net/

                                                set -o nounset

                                                # See
                                                # https://wiki.samba.org/index.php/Mounting_samba_shares_from_a_unix_client
                                                # https://access.redhat.com/solutions/448263
                                                # and also
                                                # https://serverfault.com/questions/309429/mount-cifs-credentials-file-has-special-character

                                                # One needs to run "yum install cifs-utils" to have the kernel module, man page
                                                # and other stuff.

                                                rpm --query cifs-utils > /dev/null

                                                if [[ $? != 0 ]]; then
                                                echo "Package cifs-utils is not installed -- exiting" >&2
                                                exit 1
                                                else
                                                ver=$(rpm --query cifs-utils)
                                                echo "Package $ver exists ... good!" >&2
                                                fi

                                                # Where to find credentials? Use the "credential file" approach, which
                                                # we call "authfile". Example content (w/o the leading #) below.
                                                # Make sure there are no spaces around '=' (this is different than
                                                # for "smbclient" which can deal with spaces around '='.)
                                                # ----8<------8<----------------
                                                # username=prisoner
                                                # password=KAR120C
                                                # domain=VILLAGE
                                                # ----8<------8<----------------
                                                # Trailing empty lines will lead to (harmless) error messages
                                                # "Credential formatted incorrectly: (null)"

                                                authfile='/etc/smb.passwd' # Make sure read permissions are restricted!!

                                                # Server to contact.
                                                # In the UNC path, we will use DNS name instead of the (more correct?)
                                                # NetBIOS name.
                                                # mount.cifs manpage says: "To mount using the cifs client, a tcp name
                                                # (rather than netbios name) must be specified for the server."

                                                server_dns=thedome.example.com

                                                # The name of the connecting client, just to be sure (probably useless)

                                                client_nbs=$(hostname --short | tr '[:lower:]' '[:upper]')

                                                if [[ -z $client_nbs ]]; then
                                                client_nbs=UNKNOWN
                                                fi

                                                # Connect to a certain service (which is a fileservice)
                                                # and then switch to the given directory.
                                                # Instead of appending $directory to form the complete UNC
                                                # (Uniform Naming Convention) path, one could also use the option
                                                # "prefixpath".
                                                # If there is no need to mount a subdirectory of the service,
                                                # the UNC would just be unc="//$server_dns/$service_name"

                                                service_name='information'
                                                directory='PERSONALDATA'

                                                unc="//$server_dns/$service_name/$directory"

                                                # Finally, we will mount the CIFS filesystem here (the
                                                # permissions on that node are not directly of interest)

                                                mntpoint=/mnt/portal

                                                if [[ ! -d "$mntpoint" ]]; then
                                                mkdir "$mntpoint"
                                                if [[ $? != 0 ]]; then
                                                echo "Could not create mountpoint '$mntpoint' -- exiting" >&2
                                                exit 1
                                                fi
                                                fi

                                                # Only this user will be able to access the mounted CIFS filesystem

                                                user=number6
                                                group=number6

                                                # Try to mount this so that only user "number6" can access it

                                                mount -t cifs
                                                "$unc"
                                                "$mntpoint"
                                                --read-write
                                                --verbose
                                                -o "credentials=$authfile,uid=$user,gid=$group,netbiosname=$client_nbs,file_mode=0660,dir_mode=0770"

                                                res=$?

                                                if [[ $res != 0 ]]; then
                                                echo "Mount failed!" >&2
                                                echo "Return code $res; more info may be in kernel log or daemon log" >&2
                                                echo "Try 'journalctl SYSLOG_FACILITY=0' or 'journalctl SYSLOG_FACILITY=3'" >&2
                                                echo "...exiting" >&2
                                                exit 1
                                                fi

                                                # Check permissions on the mount point

                                                stat=$(stat --format="group=%G user=%U access=%A" "$mntpoint")
                                                soll="group=$group user=$user access=drwxrwx---"

                                                if [[ $stat != "$soll" ]]; then
                                                echo "Incorrect permissions on root of '$mntpoint'" >&2
                                                echo "Expected: $soll" >&2
                                                echo "Obtained: $stat" >&2
                                                echo "...exiting" >&2
                                                umount "$mntpoint"
                                                exit 1
                                                fi

                                                # CD to the mountpoint to be sure

                                                cd "$mntpoint"

                                                if [[ $? != 0 ]]; then
                                                echo "Could not cd to '$mntpoint'" >&2
                                                exit 1
                                                fi

                                                # CD to directory TEST which must exist (change as appropriate)

                                                newcd="$mntpoint/TEST"

                                                if [[ ! -d "$newcd" ]]; then
                                                echo "Directory '$newcd' not found - can't test!" >&2
                                                echo "...exiting" >&2
                                                exit 1
                                                fi

                                                cd "$newcd"

                                                if [[ $? != 0 ]]; then
                                                echo "Could not cd to '$newcd'" >&2
                                                exit 1
                                                fi

                                                # Create a file and check the permissions

                                                testfile=$(mktemp --tmpdir="$newcd")

                                                if [[ $? != 0 ]]; then
                                                echo "Could not create temporary file in '$newcd'" >&2
                                                exit 1
                                                fi

                                                stat=$(stat --format="group=%G user=%U access=%A" "$testfile")
                                                soll="group=$group user=$user access=-rw-rw----"

                                                if [[ $stat != "$soll" ]]; then
                                                echo "Incorrect permissions on temporary file '$testfile'" >&2
                                                echo "Expected: $soll" >&2
                                                echo "Obtained: $stat" >&2
                                                echo "...exiting" >&2
                                                exit 1
                                                fi

                                                /bin/rm "$testfile"

                                                echo "Mounted '$unc' on '$mntpoint'" >&2






                                                share|improve this answer












                                                share|improve this answer



                                                share|improve this answer










                                                answered Dec 4 '17 at 15:43









                                                David TonhoferDavid Tonhofer

                                                1177




                                                1177























                                                    1














                                                    how the different mounting methods work has been exhausted, but there's something you might want to consider



                                                    if you don't want to enter your credentials directly into /etc/fstab you can use a mount option instead:
                                                    credentials=/your/path/here/.credentials



                                                    this should contain
                                                    username=msusername
                                                    password=mspassword



                                                    Save the file and exit your choice editor.



                                                    permissions should be changed to
                                                    chmod 600



                                                    if you have an encrypted home directory and want your mount to be up on boot make sure to place the file outside your home directory.
                                                    in /etc/ or /media/ might be a suitable and easily memorable place.






                                                    share|improve this answer




























                                                      1














                                                      how the different mounting methods work has been exhausted, but there's something you might want to consider



                                                      if you don't want to enter your credentials directly into /etc/fstab you can use a mount option instead:
                                                      credentials=/your/path/here/.credentials



                                                      this should contain
                                                      username=msusername
                                                      password=mspassword



                                                      Save the file and exit your choice editor.



                                                      permissions should be changed to
                                                      chmod 600



                                                      if you have an encrypted home directory and want your mount to be up on boot make sure to place the file outside your home directory.
                                                      in /etc/ or /media/ might be a suitable and easily memorable place.






                                                      share|improve this answer


























                                                        1












                                                        1








                                                        1







                                                        how the different mounting methods work has been exhausted, but there's something you might want to consider



                                                        if you don't want to enter your credentials directly into /etc/fstab you can use a mount option instead:
                                                        credentials=/your/path/here/.credentials



                                                        this should contain
                                                        username=msusername
                                                        password=mspassword



                                                        Save the file and exit your choice editor.



                                                        permissions should be changed to
                                                        chmod 600



                                                        if you have an encrypted home directory and want your mount to be up on boot make sure to place the file outside your home directory.
                                                        in /etc/ or /media/ might be a suitable and easily memorable place.






                                                        share|improve this answer













                                                        how the different mounting methods work has been exhausted, but there's something you might want to consider



                                                        if you don't want to enter your credentials directly into /etc/fstab you can use a mount option instead:
                                                        credentials=/your/path/here/.credentials



                                                        this should contain
                                                        username=msusername
                                                        password=mspassword



                                                        Save the file and exit your choice editor.



                                                        permissions should be changed to
                                                        chmod 600



                                                        if you have an encrypted home directory and want your mount to be up on boot make sure to place the file outside your home directory.
                                                        in /etc/ or /media/ might be a suitable and easily memorable place.







                                                        share|improve this answer












                                                        share|improve this answer



                                                        share|improve this answer










                                                        answered Apr 29 '18 at 14:47









                                                        amon sanamon san

                                                        7619




                                                        7619






























                                                            draft saved

                                                            draft discarded




















































                                                            Thanks for contributing an answer to Ask Ubuntu!


                                                            • Please be sure to answer the question. Provide details and share your research!

                                                            But avoid



                                                            • Asking for help, clarification, or responding to other answers.

                                                            • Making statements based on opinion; back them up with references or personal experience.


                                                            To learn more, see our tips on writing great answers.




                                                            draft saved


                                                            draft discarded














                                                            StackExchange.ready(
                                                            function () {
                                                            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f101029%2fhow-do-i-mount-a-cifs-share%23new-answer', 'question_page');
                                                            }
                                                            );

                                                            Post as a guest















                                                            Required, but never shown





















































                                                            Required, but never shown














                                                            Required, but never shown












                                                            Required, but never shown







                                                            Required, but never shown

































                                                            Required, but never shown














                                                            Required, but never shown












                                                            Required, but never shown







                                                            Required, but never shown







                                                            Popular posts from this blog

                                                            數位音樂下載

                                                            When can things happen in Etherscan, such as the picture below?

                                                            格利澤436b