71 votes

Comment monter un partage CIFS ?

J'utilise Ubuntu 11.10, et j'essaie de monter un serveur freenas. J'ai configuré le serveur pour qu'il soit partagé dans cifs y nfs sans succès.

J'ai essayé smbmount //192.168.1.### /mnt/

Je ne suis pas un nouveau venu sur Ubuntu mais je suis loin d'être un utilisateur expérimenté, je préférerais donc une option d'interface graphique si elle est disponible.

Comment monter un cifs partager en 11.10 ?

3voto

Amit Vujic Points 160
  1. Il existe un problème spécifique possible et très frustrant à résoudre lorsque les versions de CIF/SMB ne sont pas compatibles entre Linux et Windows. Dans ce cas, vous pouvez simplement faire un changement mineur dans la ligne fstab en ajoutant "vers=2.1".

    Donc, si le serveur Windows ou SMB est sur l'adresse IP 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. Les étapes 2, 3 et 4 restent les mêmes que dans la réponse précédente.

1voto

David Tonhofer Points 117

J'ai mis en place un petit script (il est destiné à Fedora cependant) pour monter le système de fichiers CIFS à partir de la ligne de commande et créer/supprimer un fichier de test. Cela peut être utile :

#!/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

1voto

Robin chan Points 161

Comment les différentes méthodes de montage fonctionnent a été épuisé, mais il y a quelque chose que vous pourriez vouloir considérer

si vous ne voulez pas entrer vos informations d'identification directement dans /etc/fstab, vous pouvez utiliser une option de montage à la place : credentials=/votre/chemin/ici/.credentials

ce qui devrait contenir username=msusername password=mpassword

Sauvegardez le fichier et quittez votre éditeur de choix.

Les permissions doivent être modifiées en chmod 600

si vous avez un répertoire personnel crypté et que vous voulez que votre montage soit actif au démarrage, assurez-vous de placer le fichier en dehors de votre répertoire personnel. dans /etc/ ou /media/ pourrait être un endroit approprié et facilement mémorisable.

SistemesEz.com

SystemesEZ est une communauté de sysadmins où vous pouvez résoudre vos problèmes et vos doutes. Vous pouvez consulter les questions des autres sysadmins, poser vos propres questions ou résoudre celles des autres.

Powered by:

X