64

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?

88

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.

  • 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
13

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
  • 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.
  • 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://".

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 
    
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.

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
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.