个人工具

UbuntuHelp:MountWindowsSharesPermanently

来自Ubuntu中文

Oneleaf讨论 | 贡献2007年5月13日 (日) 11:22的版本 (New page: {{From|https://help.ubuntu.com/community/MountWindowsSharesPermanently}} {{Languages|php5}} This page is being developed to fix a dead link on the InternetAndNetworking page. == Introdu...)

(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)
跳转至: 导航, 搜索


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.

Prerequisites

You must have smbfs installed on your machine. This should occur by default. If you don't have it, run

sudo apt-get install smbfs 
</code>

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

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

== Setup ==

=== Read/Write Group ===
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.  

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.

=== 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 .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:
<pre>
username=MyUserName
password=MyPassword
</code>

On the command line, in the directory of .smbpassword type
<pre>
sudo chown root .smbpassword
sudo chmod 600 .smbpassword 
</code>
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.

Add a line at the bottom of your \etc\fstab file that specifies:
<pre>
//servername/sharename /mountdirectory smbfs credentials=/home/myhomedirectory/.smbpassword,gid=GIDFromAbove 0 0
</code>
''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. 
You can find the UsersID in /etc/passwd
<pre>
less /etc/passwd

and then type / -followed by the username you are looking for-
</code>

Be sure to use unix "//" and "/" instead of windows "\\" and "\" in the windows share, otherwise it won't parse correctly.

Make sure the /mountdirector is a directory that exists (and is empty)

=== Completing Setup ===
Reload fstab or restart

Reloading fstab can be done by typing:
<pre>
sudo mount -a
</code>

== Troubleshooting ==

=== 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. <code>ls</code>) and refusing to go away (e.g., <code>umount</code> says that the "device is busy").  

Sometimes, all you need to do is restart the Samba daemon on the server machine.
<pre>
sudo /etc/init.d/samba restart
</code>

If that doesn't work, or for some reason you can't do anything on the server side, then try
<pre>
sudo umount -lf /mount/point
</code>
The <code>-f</code> option forces (possibly unclean) unmounting, and the <code>-l</code> option is for "lazy unmounting", and seems to work around "device is busy" errors that occur with just <code>-f</code>.  

----
CategoryDocumentation

[[category:UbuntuHelp]]