个人工具

“UbuntuHelp:MountWindowsSharesPermanently”的版本间的差异

来自Ubuntu中文

跳转至: 导航, 搜索
第7行: 第7行:
 
== Introduction ==
 
== Introduction ==
  
This guide will show you how to setup a mount of a remote windows share, and have it always there when you startup.   
+
This guide will show you how to setup a mount of a remote windows share, and have it always there when you startup.
 +
 
 +
=== Two methods, depending on share host ===
 +
 
 +
* cifs - kernel module (installed by default?)
 +
* smbfs - package
 +
 
 +
smbfs is the "original" method.
 +
 
 +
However, smbfs is not compatible with security signatures, which are enabled by default and not recommended to disable on Windows Server 2003 and laterIf a share is served by Windows Server 2003 or later, you should use cifs.
  
 
== Prerequisites ==
 
== Prerequisites ==
  
You must have smbfs installed on your machine.  This should occur by default.  If you don't have it, run  
+
You must have a windows machine (or other machine running Samba) with an accessible share.
 +
 
 +
The 'samba' package itself is not necessary if you only need a smb client.
 +
 
 +
=== smbfs ===
 +
 
 +
You may have smbfs installed on your machine.  If not, run  
 
<pre><nowiki>
 
<pre><nowiki>
 
sudo apt-get install smbfs  
 
sudo apt-get install smbfs  
 
</nowiki></pre>
 
</nowiki></pre>
  
You must have a windows machine (or other machine running Samba) with an accessable share.
+
=== cifs ===
  
The 'samba' package itself is not necessary if you only need a smb client.
+
this kernel module should be installed by default
  
 
== Setup ==
 
== Setup ==
  
=== Read/Write Group ===
+
=== Single User ===
The first step is to create a group of users that you want to have read/write access to this share (by default only root can r/w)If there is only one user you want to give read/write access, then don't worry about this.  If you have multiple users, and each user also has a windows account with individual permissions, do not add them to this group.  Instead, repeat this set of instructions for each user, I would recommend making the mount point in this example somewhere in their home directory. 
+
Note the UID of the single user which is to have access to the share.  For a user named $username, the following command outputs the UID
  
To create the group, go to the "System" menu, then to the "Administration" menu, then select "Users and Groups". Under the groups tab, create a new group.  Then add the users you want to have read/write access to this group.  Write down the GID for the group, you will need it later.
+
<pre><nowiki>
 +
grep $username /etc/passwd | cut -d: -f3
 +
</nowiki></pre>
 +
 
 +
=== Multiple Users ===
 +
If multiple users are to have the same level of access to the share, then create a new user group, presumably named after the share.
 +
 
 +
Navigate to "System" -> "Administration" -> "Users and Groups" -> "Manage Groups". -> "Add Group" and select a name, Group ID (GID), and group membersNote the GID -- you will need it later.
  
 
=== Credentials File ===
 
=== Credentials File ===
 
Warning- this method is not completely secure, any user with root access could see your password in plain text.   
 
Warning- this method is not completely secure, any user with root access could see your password in plain text.   
  
Create a file called .smbpassword, probably in the home directory of the primary user of the share.  In this file put username an equals sign and the windows username (and domain if loging into a domain) on the first line, put password an equals sign and the password for that user account on the second line of the file.  The file should look like:
+
Create a file called .smbcredentials, probably in the home directory of the primary user of the share.  In this file put username an equals sign and the windows username (and domain if loging into a domain) on the first line, put password an equals sign and the password for that user account on the second line of the file.  The file should look like:
 
<pre><nowiki>
 
<pre><nowiki>
username=MyUserName
+
username=MyUsername
 
password=MyPassword
 
password=MyPassword
 +
 +
# OR:
 +
# username=MyUsername@MyDomain
 +
# password=MyPassword
 
</nowiki></pre>
 
</nowiki></pre>
  
On the command line, in the directory of .smbpassword type
+
On the command line, in the directory of .smbcredentials type
 
<pre><nowiki>
 
<pre><nowiki>
sudo chown root .smbpassword
+
sudo chown root .smbcredentials
sudo chmod 600 .smbpassword
+
sudo chmod 600 .smbcredentials
 
</nowiki></pre>
 
</nowiki></pre>
 
this will ensure that only root can access this file.
 
this will ensure that only root can access this file.
第46行: 第72行:
 
Warning- editing the fstab file can be dangerous, please back it up before continuing.
 
Warning- editing the fstab file can be dangerous, please back it up before continuing.
  
Add a line at the bottom of your \etc\fstab file that specifies:
+
Note: if servername or sharename has a literal space (i.e. ' '), substitute \040 instead, so that 'server name' becomes 'server\040name'
 +
 
 +
Add a line at the bottom of your /etc/fstab file that specifies:
 +
 
 +
//$SERVER/$SHARE $MOUNTPOINT $FS_TYPE credentials=$SMB_CREDENTIALS,uid=$UID,gid=$GID
 +
 
 
<pre><nowiki>
 
<pre><nowiki>
//servername/sharename /mountdirectory smbfs credentials=/home/myhomedirectory/.smbpassword,gid=GIDFromAbove 0 0
+
# e.g.
 +
SERVER=apollo
 +
SHARE=install_files
 +
MOUNTPOINT=/path/to/mnt
 +
FS_TYPE=smbfs
 +
SMB_CREDENTIALS=/path/to/.smbcredentials
 +
UID=1000
 +
GID=1000
 
</nowiki></pre>
 
</nowiki></pre>
''I can't make the above show up on one line, but it MUST all be on one line in your fstab file''
 
  
If you only want one user to have read/write access, use uid=UsersID instead of the gid.  If you don't want anyone except root to have read/write access, leave that string out entirely.
+
==== smbfs, group perms ====
You can find the UsersID in /etc/passwd
+
* FS_TYPE=smbfs
 +
* GID=1234 # the newly created group's ID
 +
* don't include uid=$UID, which defaults to that of root
 
<pre><nowiki>
 
<pre><nowiki>
less /etc/passwd
+
//apollo/install_files /path/to/mnt smbfs credentials=/path/to/.smbcredentials,gid=1234 0 0
 +
</nowiki></pre>
 +
Note: many directories are set so that only the user can write to the directory and that the group can only read (permissions 755), if this is the case then when it is mounted the group will still not be able to write to the directory regardless of their permission on the share. To give the group write permissions on the mount then use the following.
 +
<pre><nowiki>
 +
//apollo/install_files /path/to/mnt smbfs credentials=/path/to/.smbcredentials,dmask=775,gid=1234 0 0
 +
</nowiki></pre>
  
and then type / -followed by the username you are looking for-
+
==== smbfs, user perms ====
 +
* FS_TYPE=smbfs
 +
* UID=1000 # particular user's uid
 +
* don't include gid=$GID, which defaults to $UID
 +
<pre><nowiki>
 +
//apollo/install_files /path/to/mnt smbfs credentials=/path/to/.smbcredentials,uid=1000 0 0
 
</nowiki></pre>
 
</nowiki></pre>
  
Be sure to use unix "//" and "/" instead of windows "\\" and "\" in the windows share, otherwise it won't parse correctly.
+
==== cifs, group perms ====
 +
* FS_TYPE=cifs
 +
* GID=1234 # the newly created group's ID
 +
* don't include uid=$UID
 +
<pre><nowiki>
 +
//apollo/install_files /path/to/mnt cifs credentials=/path/to/.smbcredentials,gid=1234 0 0
 +
</nowiki></pre>
 +
Note: many directories are set so that only the user can write to the directory and that the group can only read (permissions 755), if this is the case then when it is mounted the group will still not be able to write to the directory regardless of their permission on the share. To give the group write permissions on the mount then use the following.
 +
<pre><nowiki>
 +
//apollo/install_files /path/to/mnt smbfs credentials=/path/to/.smbcredentials,dir_mode=0775,gid=1234 0 0
 +
</nowiki></pre>
 +
==== cifs, user perms ====
 +
* FS_TYPE=cifs
 +
* UID=1000 # the user's uid
 +
* don't include gid=$GID
 +
<pre><nowiki>
 +
//apollo/install_files /path/to/mnt cifs credentials=/path/to/.smbcredentials,uid=1000 0 0
 +
</nowiki></pre>
  
Make sure the /mountdirector is a directory that exists (and is empty)
+
=== Ensure ===
  
=== Completing Setup ===
+
* The entire expression MUST all be on one line in your fstab file
Reload fstab or restart
+
* use "//" and "/" instead of "\\" and "\" when specifying the share location
 +
* /path/to/mnt is a directory that exists (and is empty)
  
Reloading fstab can be done by typing:
+
=== Completing Setup ===
 +
Reload fstab:
 
<pre><nowiki>
 
<pre><nowiki>
 
sudo mount -a
 
sudo mount -a
第73行: 第141行:
  
 
== Troubleshooting ==
 
== Troubleshooting ==
 +
 +
=== cifs will not mount ===
 +
Note:- cifs by default does not resolve netbios names so you may get an error message when you try to mount that the name could not be resolved into an address and "could not find target server".
 +
In order to enable netbios resolution you need to edit /etc/nsswitch.conf and add the winbind package:
 +
* edit /etc/nsswitch.conf
 +
<pre><nowiki>
 +
sudo gedit /etc/nsswitch.conf
 +
</nowiki></pre>
 +
change the line from
 +
<pre><nowiki>
 +
hosts: files dns
 +
</nowiki></pre>
 +
to
 +
<pre><nowiki>
 +
hosts: files dns wins
 +
</nowiki></pre>
 +
* next install winbind
 +
<pre><nowiki>
 +
sudo aptitude install winbind
 +
</nowiki></pre>
 +
Now you should be able to mount the directory
 +
 +
  
 
=== Server is down, filesystem is hung ===
 
=== Server is down, filesystem is hung ===

2007年11月21日 (三) 18:44的版本


This page is being developed to fix a dead link on the InternetAndNetworking page.

Introduction

This guide will show you how to setup a mount of a remote windows share, and have it always there when you startup.

Two methods, depending on share host

  • cifs - kernel module (installed by default?)
  • smbfs - package

smbfs is the "original" method.

However, smbfs is not compatible with security signatures, which are enabled by default and not recommended to disable on Windows Server 2003 and later. If a share is served by Windows Server 2003 or later, you should use cifs.

Prerequisites

You must have a windows machine (or other machine running Samba) with an accessible share.

The 'samba' package itself is not necessary if you only need a smb client.

smbfs

You may have smbfs installed on your machine. If not, run

sudo apt-get install smbfs 

cifs

this kernel module should be installed by default

Setup

Single User

Note the UID of the single user which is to have access to the share. For a user named $username, the following command outputs the UID

grep $username /etc/passwd | cut -d: -f3

Multiple Users

If multiple users are to have the same level of access to the share, then create a new user group, presumably named after the share.

Navigate to "System" -> "Administration" -> "Users and Groups" -> "Manage Groups". -> "Add Group" and select a name, Group ID (GID), and group members. Note the GID -- you will need it later.

Credentials File

Warning- this method is not completely secure, any user with root access could see your password in plain text.

Create a file called .smbcredentials, probably in the home directory of the primary user of the share. In this file put username an equals sign and the windows username (and domain if loging into a domain) on the first line, put password an equals sign and the password for that user account on the second line of the file. The file should look like:

username=MyUsername
password=MyPassword

# OR:
# username=MyUsername@MyDomain
# password=MyPassword

On the command line, in the directory of .smbcredentials type

sudo chown root .smbcredentials
sudo chmod 600 .smbcredentials 

this will ensure that only root can access this file.

Editing fstab

Warning- editing the fstab file can be dangerous, please back it up before continuing.

Note: if servername or sharename has a literal space (i.e. ' '), substitute \040 instead, so that 'server name' becomes 'server\040name'

Add a line at the bottom of your /etc/fstab file that specifies:

//$SERVER/$SHARE $MOUNTPOINT $FS_TYPE credentials=$SMB_CREDENTIALS,uid=$UID,gid=$GID

# e.g.
SERVER=apollo
SHARE=install_files
MOUNTPOINT=/path/to/mnt
FS_TYPE=smbfs
SMB_CREDENTIALS=/path/to/.smbcredentials
UID=1000
GID=1000

smbfs, group perms

  • FS_TYPE=smbfs
  • GID=1234 # the newly created group's ID
  • don't include uid=$UID, which defaults to that of root
//apollo/install_files /path/to/mnt smbfs credentials=/path/to/.smbcredentials,gid=1234 0 0

Note: many directories are set so that only the user can write to the directory and that the group can only read (permissions 755), if this is the case then when it is mounted the group will still not be able to write to the directory regardless of their permission on the share. To give the group write permissions on the mount then use the following.

//apollo/install_files /path/to/mnt smbfs credentials=/path/to/.smbcredentials,dmask=775,gid=1234 0 0

smbfs, user perms

  • FS_TYPE=smbfs
  • UID=1000 # particular user's uid
  • don't include gid=$GID, which defaults to $UID
//apollo/install_files /path/to/mnt smbfs credentials=/path/to/.smbcredentials,uid=1000 0 0

cifs, group perms

  • FS_TYPE=cifs
  • GID=1234 # the newly created group's ID
  • don't include uid=$UID
//apollo/install_files /path/to/mnt cifs credentials=/path/to/.smbcredentials,gid=1234 0 0

Note: many directories are set so that only the user can write to the directory and that the group can only read (permissions 755), if this is the case then when it is mounted the group will still not be able to write to the directory regardless of their permission on the share. To give the group write permissions on the mount then use the following.

//apollo/install_files /path/to/mnt smbfs credentials=/path/to/.smbcredentials,dir_mode=0775,gid=1234 0 0

cifs, user perms

  • FS_TYPE=cifs
  • UID=1000 # the user's uid
  • don't include gid=$GID
//apollo/install_files /path/to/mnt cifs credentials=/path/to/.smbcredentials,uid=1000 0 0

Ensure

  • The entire expression MUST all be on one line in your fstab file
  • use "//" and "/" instead of "\\" and "\" when specifying the share location
  • /path/to/mnt is a directory that exists (and is empty)

Completing Setup

Reload fstab:

sudo mount -a

Troubleshooting

cifs will not mount

Note:- cifs by default does not resolve netbios names so you may get an error message when you try to mount that the name could not be resolved into an address and "could not find target server". In order to enable netbios resolution you need to edit /etc/nsswitch.conf and add the winbind package:

  • edit /etc/nsswitch.conf
sudo gedit /etc/nsswitch.conf

change the line from

hosts: files dns

to

hosts: files dns wins
  • next install winbind
sudo aptitude install winbind

Now you should be able to mount the directory


Server is down, filesystem is hung

If the client somehow loses contact with the Samba server, then the filesystem will probably get hung. Basically, it becomes a blackhole, eating things that try to read to/write from it (e.g. ls) and refusing to go away (e.g., umount says that the "device is busy").

Sometimes, all you need to do is restart the Samba daemon on the server machine.

sudo /etc/init.d/samba restart

If that doesn't work, or for some reason you can't do anything on the server side, then try

sudo umount -lf /mount/point

The -f option forces (possibly unclean) unmounting, and the -l option is for "lazy unmounting", and seems to work around "device is busy" errors that occur with just -f.