Mounting cifs share linux

How do I mount a CIFS share?

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?

Has anyone explained what error 95 might be? The message si «operation not supported», but it doesn’t say what «operation».

8 Answers 8

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.

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:

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.

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

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

@MarcoPashkov cifs-utils is what got me up and going. None of this would work otherwise. This should be directly included in the 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.

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) My samba share shows in Caja (the ubuntu 16.04 „explorer“) as

Читайте также:  Kali linux persistence gparted

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.

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.

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

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://».

  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 
mkdir /mnt/linux_smb chmod 755 /mnt/linux_smb 
  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 

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

Источник

Читайте также:  Adb and fastboot on linux

Linux — монтируем шару CIFS

Linux

CIFS (Common Internet File System) — протокол передачи данных по сети с одного устройства на другое. CIFS также называют SMB (Server Message Block). Пример: сетевая папка или диск для общего доступа.

Для работы CIFS/SMB необходимы порты:

Для предоставления удалённого доступа используется TCP 445. Для разрешения имен NetBios используются порты UDP 137, 138 и TCP 139, без них будет работать только обращение по IP адресу.

В Windows поддержка CIFS/SMB есть по умолчанию. В Linux CIFS/SMB реализуется с помощью samba.

Ссылки

Установка пакета для работы CIFS

Монтирование CIFS вручную

mount.cifs или mount -t cifs

Пример монтирования общей папки public на сервере с IP адресом 10.20.30.40 в локальную папку /mnt:

mount.cifs //10.20.30.40/public /mnt

Пример монтирования папки share на сервере с IP адресом 10.20.30.40 в локальную папку /mnt от имени пользователя v.pupkin:

mount.cifs //10.20.30.40/share /mnt -o user=v.pupkin

Пример монтирования папки share на сервере с IP адресом 10.20.30.40 в локальную папку /mnt от имени пользователя v.pupkin в домене ilab.local:

mount.cifs //10.20.30.40/share /mnt -o user=v.pupkin,domain=ilab.local

Монтирование CIFS автоматически через fstab

Создаём файл для хранения логина и пароля. Лучше скрытый.

username=v.pupkin password=MySecretPassw0rd domain=ilab.local

Добавляем строку в /etc/fstab:

//10.20.30.40/share /mnt cifs user,rw,credentials=/root/.smbshare 0 0
  • //10.20.30.40/share — путь к монтируемой папке
  • /mnt — локальная папка для монтирования
  • cifs — тип файловой системы
  • user — позволяет монтировать любому пользователю
  • rw — чтение/запись
  • credentials — путь к файлу с логином и паролем для монтирования
  • 0 — индикатор резервной копии (0 — не используется)
  • 0 — порядок проверки раздела (0 — не проверять)

Монтируем перезагрузкой или командой:

Дополнительно

Монтирование CIFS с пробелом (заменяем пробел на \040):

//10.20.30.40/share\040with\040spaces /mnt cifs user,rw,credentials=/root/.smbshare 0 0

Монтировать от гостевой учётной записи:

//10.20.30.40/share /mnt cifs guest 0 0

Указать версию протокола SMB 3.0:

//10.20.30.40/share /mnt cifs user,rw,credentials=/root/.smbshare,vers=3.0 0 0

Монтировать под пользователем:

//10.20.30.40/share /mnt cifs defaults,uid=v.pupkin,gid=v.pupkin.group,rw,credentials=/root/.smbshare,vers=3.0 0 0
//10.20.30.40/share /mnt cifs defaults,uid=222,gid=222,rw,credentials=/root/.smbshare,vers=3.0,file_mode=0600,dir_mode=0700 0 0

Намекаем на виндовую шару:

//10.20.30.40/share /mnt cifs defaults,uid=222,gid=222,rw,credentials=/root/.smbshare,vers=3.0,file_mode=0600,dir_mode=0700,nounix 0 0
//fs.ilab.local/новая\040папка /mnt cifs defaults,uid=www-data,gid=www-data,rw,credentials=/root/.smbshare,vers=3.0,file_mode=0600,dir_mode=0700,nounix,codepage=cp1251,iocharset=utf8 0 0 

Теги

Похожие материалы

Установка VMware Tools на Ubuntu

Олег

Ubuntu

VMware Tools — бесплатный набор утилит для улучшения взаимодействия виртуальной машины и платформы VMware. В Интернете пишут про то, что от установки VMware Tools улучшается производительность виртуальной машины. В качестве примера указывают на то, что только в этом наборе утилит есть драйвера для сетевой карты vmxnet3. Не согласен, драйвера можно и отдельно поставить. В linux так и без этих драйверов сетевая карта работает нормально. А вот если у вас Windows Server — рекомендую vmxnet3, меньше глюков.

Читайте также:  Лучшие ssh клиенты для linux

Источник

Оцените статью
Adblock
detector