如何挂载CIFS共享?

我正在使用Ubuntu 11.10,我正在尝试安装freenas服务器。 我有服务器设置分享cifsnfs没有运气。

我试过smbmount //192.168.1.### /mnt/

我不是Ubuntu的新手但是远不及高级用户,所以我更喜欢GUI选项(如果有的话)。

如何在11.10中挂载cifs共享?

pyNeighborhood是安装samba共享的gui,可在软件中心下载。

这里有一篇很好的文章介绍如何设置和使用它。

首先安装cifs utils

 sudo apt-get install cifs-utils 

或者,基本终端命令是:

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

如果你想在Nautilus中看到你的装载,最好先在/ media / USERNAME /中创建一个子文件夹,例如:

 mkdir /media/paul/cifsShare 

另外,例如,mount命令中可以省略密码(也将演示文件/文件夹模式):

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

在这种情况下,您将被要求输入密码(实际上是2个密码)。

请阅读Samba文档 ,了解如何执行此操作并正确设置以在启动时安装等。

就像map7所说的那样,但如果你不想每次更改驱动器上的文件时都使用root权限,那么你必须挂载到用户文件夹,并确保将gid和uid设置为你的用户名。

命令设置它们:

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

请注意, mnt文件夹是在~/mnt/share而不是/mnt/share

如果您希望它提示您而不是您在命令中使用密码= PASSWD,也可以省略密码= PASSWD,该命令可能存储在您的shell历史记录中:

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

1)我的samba分享在Caja(ubuntu 16.04“explorer”)中显示为

 smb://thinkpad/ddrive/ 

这是一个很好的岩石测试,没有连接/路径问题。

(请注意 :如果caja询问您的Windows机器密码凭据,您可能需要将Domain从WORKGROUP切换到机器名称,即’thinkpad’。然后驱动器的真正本地登录凭据应该这样做。)

2)如果有效,这里有命令:

 sudo mount -t cifs -o username=frank //thinkpad/ddrive /mnt/ddrive 
  • 事先确保/ mnt / ddrive作为空目录存在。
  • 你也可以在username =之后直接添加一个,password=supersecret (没有空格),但是当你输入命令时,你也可以等待提示。

我不同意声称root始终是使cifs连接所必需的。 确实,CLI smbmount总是需要它,但是像nautilus这样的文件管理器能够挂载cifs共享,并且不必是root用户。

我不使用Gnome,但我仍然安装了Nautilus。 在终端中运行此命令以防止它尝试接管桌面

 $ nautilus --no-desktop & 

在Ubuntu 16.04中,左侧树菜单底部有“连接到服务器”。 点击它,建议是“smb://foo.example.com”。 smb是“cifs”的旧词,如果你放入你的服务器并在开始时与smb://共享,连接确实有效! 我承诺。 如果您的共享是一个已命名的东西,则需要在斜杠后面显示“smb://foo.example.com/myshare”。

我以同样的方式使用了其他文件管理器。 协议必须是“smb://”。

  1. 您可以将所有这些详细信息放在/ etc / fstab中,以便在系统启动时安装目录。 如果Windows或SMB服务器的IP地址为192.168.1.1

     /etc/fstab //192.168.1.1/SharedFolder/ /mnt/linux_smb cifs username=winuser,password=TopSecret 0 0 
  2. 创建目录为linux挂载点

     mkdir /mnt/linux_smb chmod 755 /mnt/linux_smb 
  3. 第一次手动安装

     mount -a 
  4. 可以找到最终的错误

     dmesg | tail 
  1. 当Linux和Windows之间的CIF / SMB版本不兼容时,可能会遇到特定问题且非常令人沮丧。 在这种情况下,您可以在fstab行中添加“vers = 2.1”来制作小的chnage

    因此,如果Windows或SMB服务器的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. 步骤2,3和4与之前的答案保持一致。

我整理了一个小脚本(虽然它适用于Fedora)从命令行安装CIFS文件系统并创建/删除测试文件。 可能有一些用处:

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

不同的安装方法如何工作已经用尽,但您可能需要考虑一些事项

如果您不想直接在/ etc / fstab中输入凭据,则可以使用mount选项:credentials = / your / path / here / .credentials

这应该包含username = msusername password = mspassword

保存文件并退出选择编辑器。

权限应更改为chmod 600

如果您有一个加密的主目录并希望您的挂载启动,请确保将该文件放在您的主目录之外。 在/ etc /或/ media /中可能是一个合适且容易记忆的地方。