特殊:Badtitle/NS100:ComprehensiveSambaGuide:修订间差异
小无编辑摘要 |
小无编辑摘要 |
||
第22行: | 第22行: | ||
> control netconnections </nowiki></pre> | > control netconnections </nowiki></pre> | ||
Right click on the icon of the network adapter in question and select '''Properties'''. Ensure '''File and Printer Sharing...''' is listed. If it is not you can use the '''Install''' button to install that service. | Right click on the icon of the network adapter in question and select '''Properties'''. Ensure '''File and Printer Sharing...''' is listed. If it is not you can use the '''Install''' button to install that service. | ||
[http://xtknight.atothosting.com/images/ubuntu_wiki/lanprop.jpg] | |||
<!> If you have the XP firewall enabled, ensure that '''File and Printer Sharing''' is selected under the '''Exceptions''' tab for the firewall configuration. Likewise, make sure any other firewall you are using does not restrict SMB (sharing) access. | <!> If you have the XP firewall enabled, ensure that '''File and Printer Sharing''' is selected under the '''Exceptions''' tab for the firewall configuration. Likewise, make sure any other firewall you are using does not restrict SMB (sharing) access. | ||
=== Configuring Workgroup and Computer Name === | === Configuring Workgroup and Computer Name === | ||
Right click on '''My Computer''' on the desktop and go to '''Properties'''. Choose the '''Computer Name''' tab at the top. Click '''Change...''' and use '''Workgroup'''. In this example we will use '''MSHOME''' for the workgroup name as that is also the default in Ubuntu's Samba. Also enter a computer name (in this example, '''DEVMACHINE'''). Workgroup and computer names are not case-sensitive. It is important to reboot now if it wants you to. Please reboot, don't simply log out. | Right click on '''My Computer''' on the desktop and go to '''Properties'''. Choose the '''Computer Name''' tab at the top. Click '''Change...''' and use '''Workgroup'''. In this example we will use '''MSHOME''' for the workgroup name as that is also the default in Ubuntu's Samba. Also enter a computer name (in this example, '''DEVMACHINE'''). Workgroup and computer names are not case-sensitive. It is important to reboot now if it wants you to. Please reboot, don't simply log out. | ||
[http://xtknight.atothosting.com/images/ubuntu_wiki/compname.jpg] | |||
=== Setting Up Access Control === | === Setting Up Access Control === | ||
We will need to add a group and user to effectively control access to our Windows shares. | We will need to add a group and user to effectively control access to our Windows shares. | ||
第41行: | 第41行: | ||
=== Setting Up Your Shares === | === Setting Up Your Shares === | ||
In Explorer, find a drive or folder that you would like to share. In my example I will be sharing a folder at '''c:\shares'''. Right click the folder or drive and select '''Properties'''. Go to the '''Sharing''' tab and enable '''Share this folder'''. Enter a proper '''share name''' ('''shares''' in this example). Click '''Permissions''' and remove the '''Everyone''' group from the list. Now add the '''UbuntuSMB''' group ('''Add...''' and type in '''UbuntuSMB''' and click OK). Set the desired permissions for how Ubuntu should be able to access this share (in my example, I enabled full read/write access). This should mean that nobody is allowed to access the share, except for users in the '''UbuntuSMB''' group. If you explicitly press Deny on '''Everyone''', that would also Deny '''UbuntuSMB''' since Deny has precedence over Allow and we don't want that. | In Explorer, find a drive or folder that you would like to share. In my example I will be sharing a folder at '''c:\shares'''. Right click the folder or drive and select '''Properties'''. Go to the '''Sharing''' tab and enable '''Share this folder'''. Enter a proper '''share name''' ('''shares''' in this example). Click '''Permissions''' and remove the '''Everyone''' group from the list. Now add the '''UbuntuSMB''' group ('''Add...''' and type in '''UbuntuSMB''' and click OK). Set the desired permissions for how Ubuntu should be able to access this share (in my example, I enabled full read/write access). This should mean that nobody is allowed to access the share, except for users in the '''UbuntuSMB''' group. If you explicitly press Deny on '''Everyone''', that would also Deny '''UbuntuSMB''' since Deny has precedence over Allow and we don't want that. | ||
[http://xtknight.atothosting.com/images/ubuntu_wiki/shareperms.jpg] | |||
<!> If you connect to the share by using a user that is not in the '''UbuntuSMB''' group, the connection will succeed but the mount point will not at all be accessible, even by root. The listing will appear as such: <pre><nowiki> | <!> If you connect to the share by using a user that is not in the '''UbuntuSMB''' group, the connection will succeed but the mount point will not at all be accessible, even by root. The listing will appear as such: <pre><nowiki> | ||
?--------- ? ? ? ? ? winshares </nowiki></pre> | ?--------- ? ? ? ? ? winshares </nowiki></pre> |
2008年10月19日 (日) 22:24的最新版本
文章出处: |
{{#if: | {{{2}}} | https://help.ubuntu.com/community/ComprehensiveSambaGuide }} |
点击翻译: |
English {{#ifexist: {{#if: UbuntuHelp:ComprehensiveSambaGuide | UbuntuHelp:ComprehensiveSambaGuide | {{#if: | :}}ComprehensiveSambaGuide}}/af | • {{#if: UbuntuHelp:ComprehensiveSambaGuide|Afrikaans| [[::ComprehensiveSambaGuide/af|Afrikaans]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ComprehensiveSambaGuide | UbuntuHelp:ComprehensiveSambaGuide | {{#if: | :}}ComprehensiveSambaGuide}}/ar | • {{#if: UbuntuHelp:ComprehensiveSambaGuide|العربية| [[::ComprehensiveSambaGuide/ar|العربية]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ComprehensiveSambaGuide | UbuntuHelp:ComprehensiveSambaGuide | {{#if: | :}}ComprehensiveSambaGuide}}/az | • {{#if: UbuntuHelp:ComprehensiveSambaGuide|azərbaycanca| [[::ComprehensiveSambaGuide/az|azərbaycanca]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ComprehensiveSambaGuide | UbuntuHelp:ComprehensiveSambaGuide | {{#if: | :}}ComprehensiveSambaGuide}}/bcc | • {{#if: UbuntuHelp:ComprehensiveSambaGuide|جهلسری بلوچی| [[::ComprehensiveSambaGuide/bcc|جهلسری بلوچی]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ComprehensiveSambaGuide | UbuntuHelp:ComprehensiveSambaGuide | {{#if: | :}}ComprehensiveSambaGuide}}/bg | • {{#if: UbuntuHelp:ComprehensiveSambaGuide|български| [[::ComprehensiveSambaGuide/bg|български]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ComprehensiveSambaGuide | UbuntuHelp:ComprehensiveSambaGuide | {{#if: | :}}ComprehensiveSambaGuide}}/br | • {{#if: UbuntuHelp:ComprehensiveSambaGuide|brezhoneg| [[::ComprehensiveSambaGuide/br|brezhoneg]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ComprehensiveSambaGuide | UbuntuHelp:ComprehensiveSambaGuide | {{#if: | :}}ComprehensiveSambaGuide}}/ca | • {{#if: UbuntuHelp:ComprehensiveSambaGuide|català| [[::ComprehensiveSambaGuide/ca|català]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ComprehensiveSambaGuide | UbuntuHelp:ComprehensiveSambaGuide | {{#if: | :}}ComprehensiveSambaGuide}}/cs | • {{#if: UbuntuHelp:ComprehensiveSambaGuide|čeština| [[::ComprehensiveSambaGuide/cs|čeština]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ComprehensiveSambaGuide | UbuntuHelp:ComprehensiveSambaGuide | {{#if: | :}}ComprehensiveSambaGuide}}/de | • {{#if: UbuntuHelp:ComprehensiveSambaGuide|Deutsch| [[::ComprehensiveSambaGuide/de|Deutsch]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ComprehensiveSambaGuide | UbuntuHelp:ComprehensiveSambaGuide | {{#if: | :}}ComprehensiveSambaGuide}}/el | • {{#if: UbuntuHelp:ComprehensiveSambaGuide|Ελληνικά| [[::ComprehensiveSambaGuide/el|Ελληνικά]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ComprehensiveSambaGuide | UbuntuHelp:ComprehensiveSambaGuide | {{#if: | :}}ComprehensiveSambaGuide}}/es | • {{#if: UbuntuHelp:ComprehensiveSambaGuide|español| [[::ComprehensiveSambaGuide/es|español]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ComprehensiveSambaGuide | UbuntuHelp:ComprehensiveSambaGuide | {{#if: | :}}ComprehensiveSambaGuide}}/fa | • {{#if: UbuntuHelp:ComprehensiveSambaGuide|فارسی| [[::ComprehensiveSambaGuide/fa|فارسی]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ComprehensiveSambaGuide | UbuntuHelp:ComprehensiveSambaGuide | {{#if: | :}}ComprehensiveSambaGuide}}/fi | • {{#if: UbuntuHelp:ComprehensiveSambaGuide|suomi| [[::ComprehensiveSambaGuide/fi|suomi]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ComprehensiveSambaGuide | UbuntuHelp:ComprehensiveSambaGuide | {{#if: | :}}ComprehensiveSambaGuide}}/fr | • {{#if: UbuntuHelp:ComprehensiveSambaGuide|français| [[::ComprehensiveSambaGuide/fr|français]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ComprehensiveSambaGuide | UbuntuHelp:ComprehensiveSambaGuide | {{#if: | :}}ComprehensiveSambaGuide}}/gu | • {{#if: UbuntuHelp:ComprehensiveSambaGuide|ગુજરાતી| [[::ComprehensiveSambaGuide/gu|ગુજરાતી]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ComprehensiveSambaGuide | UbuntuHelp:ComprehensiveSambaGuide | {{#if: | :}}ComprehensiveSambaGuide}}/he | • {{#if: UbuntuHelp:ComprehensiveSambaGuide|עברית| [[::ComprehensiveSambaGuide/he|עברית]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ComprehensiveSambaGuide | UbuntuHelp:ComprehensiveSambaGuide | {{#if: | :}}ComprehensiveSambaGuide}}/hu | • {{#if: UbuntuHelp:ComprehensiveSambaGuide|magyar| [[::ComprehensiveSambaGuide/hu|magyar]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ComprehensiveSambaGuide | UbuntuHelp:ComprehensiveSambaGuide | {{#if: | :}}ComprehensiveSambaGuide}}/id | • {{#if: UbuntuHelp:ComprehensiveSambaGuide|Bahasa Indonesia| [[::ComprehensiveSambaGuide/id|Bahasa Indonesia]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ComprehensiveSambaGuide | UbuntuHelp:ComprehensiveSambaGuide | {{#if: | :}}ComprehensiveSambaGuide}}/it | • {{#if: UbuntuHelp:ComprehensiveSambaGuide|italiano| [[::ComprehensiveSambaGuide/it|italiano]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ComprehensiveSambaGuide | UbuntuHelp:ComprehensiveSambaGuide | {{#if: | :}}ComprehensiveSambaGuide}}/ja | • {{#if: UbuntuHelp:ComprehensiveSambaGuide|日本語| [[::ComprehensiveSambaGuide/ja|日本語]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ComprehensiveSambaGuide | UbuntuHelp:ComprehensiveSambaGuide | {{#if: | :}}ComprehensiveSambaGuide}}/ko | • {{#if: UbuntuHelp:ComprehensiveSambaGuide|한국어| [[::ComprehensiveSambaGuide/ko|한국어]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ComprehensiveSambaGuide | UbuntuHelp:ComprehensiveSambaGuide | {{#if: | :}}ComprehensiveSambaGuide}}/ksh | • {{#if: UbuntuHelp:ComprehensiveSambaGuide|Ripoarisch| [[::ComprehensiveSambaGuide/ksh|Ripoarisch]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ComprehensiveSambaGuide | UbuntuHelp:ComprehensiveSambaGuide | {{#if: | :}}ComprehensiveSambaGuide}}/mr | • {{#if: UbuntuHelp:ComprehensiveSambaGuide|मराठी| [[::ComprehensiveSambaGuide/mr|मराठी]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ComprehensiveSambaGuide | UbuntuHelp:ComprehensiveSambaGuide | {{#if: | :}}ComprehensiveSambaGuide}}/ms | • {{#if: UbuntuHelp:ComprehensiveSambaGuide|Bahasa Melayu| [[::ComprehensiveSambaGuide/ms|Bahasa Melayu]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ComprehensiveSambaGuide | UbuntuHelp:ComprehensiveSambaGuide | {{#if: | :}}ComprehensiveSambaGuide}}/nl | • {{#if: UbuntuHelp:ComprehensiveSambaGuide|Nederlands| [[::ComprehensiveSambaGuide/nl|Nederlands]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ComprehensiveSambaGuide | UbuntuHelp:ComprehensiveSambaGuide | {{#if: | :}}ComprehensiveSambaGuide}}/no | • {{#if: UbuntuHelp:ComprehensiveSambaGuide|norsk| [[::ComprehensiveSambaGuide/no|norsk]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ComprehensiveSambaGuide | UbuntuHelp:ComprehensiveSambaGuide | {{#if: | :}}ComprehensiveSambaGuide}}/oc | • {{#if: UbuntuHelp:ComprehensiveSambaGuide|occitan| [[::ComprehensiveSambaGuide/oc|occitan]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ComprehensiveSambaGuide | UbuntuHelp:ComprehensiveSambaGuide | {{#if: | :}}ComprehensiveSambaGuide}}/pl | • {{#if: UbuntuHelp:ComprehensiveSambaGuide|polski| [[::ComprehensiveSambaGuide/pl|polski]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ComprehensiveSambaGuide | UbuntuHelp:ComprehensiveSambaGuide | {{#if: | :}}ComprehensiveSambaGuide}}/pt | • {{#if: UbuntuHelp:ComprehensiveSambaGuide|português| [[::ComprehensiveSambaGuide/pt|português]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ComprehensiveSambaGuide | UbuntuHelp:ComprehensiveSambaGuide | {{#if: | :}}ComprehensiveSambaGuide}}/ro | • {{#if: UbuntuHelp:ComprehensiveSambaGuide|română| [[::ComprehensiveSambaGuide/ro|română]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ComprehensiveSambaGuide | UbuntuHelp:ComprehensiveSambaGuide | {{#if: | :}}ComprehensiveSambaGuide}}/ru | • {{#if: UbuntuHelp:ComprehensiveSambaGuide|русский| [[::ComprehensiveSambaGuide/ru|русский]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ComprehensiveSambaGuide | UbuntuHelp:ComprehensiveSambaGuide | {{#if: | :}}ComprehensiveSambaGuide}}/si | • {{#if: UbuntuHelp:ComprehensiveSambaGuide|සිංහල| [[::ComprehensiveSambaGuide/si|සිංහල]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ComprehensiveSambaGuide | UbuntuHelp:ComprehensiveSambaGuide | {{#if: | :}}ComprehensiveSambaGuide}}/sq | • {{#if: UbuntuHelp:ComprehensiveSambaGuide|shqip| [[::ComprehensiveSambaGuide/sq|shqip]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ComprehensiveSambaGuide | UbuntuHelp:ComprehensiveSambaGuide | {{#if: | :}}ComprehensiveSambaGuide}}/sr | • {{#if: UbuntuHelp:ComprehensiveSambaGuide|српски / srpski| [[::ComprehensiveSambaGuide/sr|српски / srpski]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ComprehensiveSambaGuide | UbuntuHelp:ComprehensiveSambaGuide | {{#if: | :}}ComprehensiveSambaGuide}}/sv | • {{#if: UbuntuHelp:ComprehensiveSambaGuide|svenska| [[::ComprehensiveSambaGuide/sv|svenska]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ComprehensiveSambaGuide | UbuntuHelp:ComprehensiveSambaGuide | {{#if: | :}}ComprehensiveSambaGuide}}/th | • {{#if: UbuntuHelp:ComprehensiveSambaGuide|ไทย| [[::ComprehensiveSambaGuide/th|ไทย]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ComprehensiveSambaGuide | UbuntuHelp:ComprehensiveSambaGuide | {{#if: | :}}ComprehensiveSambaGuide}}/tr | • {{#if: UbuntuHelp:ComprehensiveSambaGuide|Türkçe| [[::ComprehensiveSambaGuide/tr|Türkçe]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ComprehensiveSambaGuide | UbuntuHelp:ComprehensiveSambaGuide | {{#if: | :}}ComprehensiveSambaGuide}}/vi | • {{#if: UbuntuHelp:ComprehensiveSambaGuide|Tiếng Việt| [[::ComprehensiveSambaGuide/vi|Tiếng Việt]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ComprehensiveSambaGuide | UbuntuHelp:ComprehensiveSambaGuide | {{#if: | :}}ComprehensiveSambaGuide}}/yue | • {{#if: UbuntuHelp:ComprehensiveSambaGuide|粵語| [[::ComprehensiveSambaGuide/yue|粵語]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ComprehensiveSambaGuide | UbuntuHelp:ComprehensiveSambaGuide | {{#if: | :}}ComprehensiveSambaGuide}}/zh | • {{#if: UbuntuHelp:ComprehensiveSambaGuide|中文| [[::ComprehensiveSambaGuide/zh|中文]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ComprehensiveSambaGuide | UbuntuHelp:ComprehensiveSambaGuide | {{#if: | :}}ComprehensiveSambaGuide}}/zh-hans | • {{#if: UbuntuHelp:ComprehensiveSambaGuide|中文(简体)| [[::ComprehensiveSambaGuide/zh-hans|中文(简体)]]}}|}} {{#ifexist: {{#if: UbuntuHelp:ComprehensiveSambaGuide | UbuntuHelp:ComprehensiveSambaGuide | {{#if: | :}}ComprehensiveSambaGuide}}/zh-hant | • {{#if: UbuntuHelp:ComprehensiveSambaGuide|中文(繁體)| [[::ComprehensiveSambaGuide/zh-hant|中文(繁體)]]}}|}} |
{{#ifeq:UbuntuHelp:ComprehensiveSambaGuide|:ComprehensiveSambaGuide|请不要直接编辑翻译本页,本页将定期与来源同步。}} |
{{#ifexist: :ComprehensiveSambaGuide/zh | | {{#ifexist: ComprehensiveSambaGuide/zh | | {{#ifeq: {{#titleparts:ComprehensiveSambaGuide|1|-1|}} | zh | | }} }} }} {{#ifeq: {{#titleparts:ComprehensiveSambaGuide|1|-1|}} | zh | | }}
Please note. This guide is out of date. Please see "man mount.cifs", find another guide, or get someone to update this guide. Please provide a link to a better guide here if you find one. Thankyou. |
This tutorial will help you setup reliable and secure sharing between Linux and Windows. It covers the steps to take for both operating systems. This guide should be compatible with the following versions of Ubuntu.
- Dapper Drake (6.06)
- Edgy Eft (6.10)
- Feisty Fawn (7.04)
It should also work on these versions of Microsoft Windows (with a Workgroup configuration, not Domain).
- Windows 2000 Professional
- Windows XP Home
- Windows XP Professional
- Windows XP 64-bit Edition
It has however only been tested on "Feisty Fawn" and "Windows XP 64-bit Edition" so far. In this guide we will set up a share on Windows and access it from Linux. This appears to be the most reliable and natural configuration. (!) Samba is Linux's implementation of Windows' SMB (Server Message Block) protocol.
Configuring SMB on Windows
Installing the SMB Protocol
Open a command prompt by going to the start menu and pressing run. Type cmd and click OK. In the command prompt, type this command (the > prefix should be ignored):
> control netconnections
Right click on the icon of the network adapter in question and select Properties. Ensure File and Printer Sharing... is listed. If it is not you can use the Install button to install that service. [1] <!> If you have the XP firewall enabled, ensure that File and Printer Sharing is selected under the Exceptions tab for the firewall configuration. Likewise, make sure any other firewall you are using does not restrict SMB (sharing) access.
Configuring Workgroup and Computer Name
Right click on My Computer on the desktop and go to Properties. Choose the Computer Name tab at the top. Click Change... and use Workgroup. In this example we will use MSHOME for the workgroup name as that is also the default in Ubuntu's Samba. Also enter a computer name (in this example, DEVMACHINE). Workgroup and computer names are not case-sensitive. It is important to reboot now if it wants you to. Please reboot, don't simply log out. [2]
Setting Up Access Control
We will need to add a group and user to effectively control access to our Windows shares.
Go back to your command line, and type these lines. Change S'hareAccessPassword' to a password of your choice.
> net localgroup UbuntuSMB /add > net user ubuntu ShareAccessPassword /add /passwordchg:no /expires:never > net localgroup UbuntuSMB ubuntu /add > net localgroup Users ubuntu /delete
We're also going to have to make sure the password never expires. Type:
> compmgmt.msc
Find the Local Users and Groups section under System Tools. Right click on the ubuntu user and select Properties. Enable Password Never Expires and click OK.
Disable Simple Sharing
This feature does not make sharing any easier; it's basically a roadblock. Open an Explorer window (just double click My Computer) and go to View->Folder Options. Click the View tab and disable Use simple file sharing. Click OK to exit the dialog.
In Explorer, find a drive or folder that you would like to share. In my example I will be sharing a folder at c:\shares. Right click the folder or drive and select Properties. Go to the Sharing tab and enable Share this folder. Enter a proper share name (shares in this example). Click Permissions and remove the Everyone group from the list. Now add the UbuntuSMB group (Add... and type in UbuntuSMB and click OK). Set the desired permissions for how Ubuntu should be able to access this share (in my example, I enabled full read/write access). This should mean that nobody is allowed to access the share, except for users in the UbuntuSMB group. If you explicitly press Deny on Everyone, that would also Deny UbuntuSMB since Deny has precedence over Allow and we don't want that. [3]
<!> If you connect to the share by using a user that is not in the UbuntuSMB group, the connection will succeed but the mount point will not at all be accessible, even by root. The listing will appear as such:
?--------- ? ? ? ? ? winshares
(!) You can change the Access Control List (ACL), the permissions, while the share is mounted without having to restart any service on either operating system. The changes will immediately take effect. [As of: Feisty Fawn; Windows XP 64-bit Edition]
Configuring Samba on Ubuntu
Installing Samba
Open a terminal by going to Applications->Accessories->Terminal and type the following.
$ sudo apt-get install samba smbfs $ sudo mkdir -p /media/winshares $ sudo addgroup smb $ sudo adduser $USER smb
You must now log out to ensure your user is now in the smb group. You do not have to reboot.
Now let's try and mount our Windows share! Remember to replace S'hareAccessPassword' with the ubuntu user's password. The user name for the login is not case-sensitive, although the password is. Also, use the proper workgroup and share names. "//DEVMACHINE/shares" is called our share path. This is a type of UNC path where the format is //COMPUTER_NAME/SHARE_NAME. In Windows, backslashes are used instead of forward slashes to access UNC paths. Recall that we used "DEVMACHINE" for our computer name and "shares" for our share name.
$ sudo mount -t smbfs -o username=ubuntu,password=ShareAccessPassword,workgroup=MSHOME,gid=smb,uid=$USER,fmask=770,dmask=770,rw //DEVMACHINE/shares /media/winshares
<!> By using the 770 permission, we are giving full access to the owner (the current user), to everybody in the smb group, and no access at all to users not in the smb group. <!> If your share name contains a space, you must enclose the share name in double quotes, e.g. for a share named "Share with Spaces":
$ sudo mount -t smbfs -o username=ubuntu,password=ShareAccessPassword,workgroup=MSHOME,gid=smb,uid=$USER,fmask=770,dmask=770,rw "//DEVMACHINE/Share with Spaces" /media/winshares
You must do something else in the fstab entry which will be mentioned later. To test another share you must specify another share path (e.g. //DEVMACHINE/shares) and target (e.g. /media/winshares).
Break Down
- sudo mount -- this is the command to mount a drive to a target.
- -t smbfs -- this specifes that we would like to use the "smbfs" (Samba) file system.
- -o username=... -- these are the parameters we pass to "smbfs" to make a proper connection to a share.
- gid=smb -- this specifies that we would like the "smb" group to have ownership of the mount point.
- fmask=777,dmask=777 -- these are the permissions we are giving to the owner, all users of the "smb" group.
- rw -- this specifies that we would like read/write access to the share. ro will do read-only.
If your terminal printed nothing, it probably mounted just fine. Verify that the permissions are what you expect.
$ stat -c %a /media/winshares
If they are different than 770 as specified, verify that you typed the mount command properly.
<!> Vital Note: you can not mount a whole computer to one location. For example, you can not mount the whole //DEVMACHINE/ computer to one folder on your Linux system. You also need to be careful about how you specify your share path. //DEVMACHINE/shares will work, but //DEVMACHINE/shares/ will return the following!
25034: tree connect failed: ERRDOS - ERRnosuchshare (You specified an invalid share name) SMB connection failed
Securing Our Password
Let's unmount every share that we may have test-mounted from the last step.
$ sudo umount -a -t smbfs
We don't want our username and password to be in plaintext and visible to everybody in /etc/fstab. Thus, we can use a credentials file that only root can see since only root should be mounting this share. Type the following.
$ sudo touch /etc/smbcredentials $ sudo chmod 600 /etc/smbcredentials
Open /etc/smbcredentials using your favorite text editor.
Ubuntu/GNOME:
$ gksu gedit /etc/smbcredentials
Kubuntu/KDE:
$ kdesu kate /etc/smbcredentials
Type the following into the /etc/smbcredentials file:
username = ubuntu password = ShareAccessPassword
Save it and close your text editor. Some text editors make a back-up of the file by appending a ~ to the filename. Let's ensure this file is removed so nobody can get our login and password. Be sure to type the ~ at the end in the following.
$ sudo rm /etc/smbcredentials~
Open /etc/fstab the same way you opened /etc/smbcredentials. For each share you want mounted at boot-up, add a line like the following.
//DEVMACHINE/shares /media/winshares smbfs auto,credentials=/etc/smbcredentials,workgroup=MSHOME,gid=smb,uid=1000,fmask=770,dmask=770,rw 0 0
uid=1000 is assumed to be the user you are using now. Change it to your current user's ID or name as necessary. This must all be on one line in fstab. It may appear word-wrapped in your text editor, but as long as there are no actual line feeds, you're fine. Save and exit your text editor.
<!> If your share name contains a space, you must replace all spaces with \040, e.g. for a share named "Share with Spaces":
//DEVMACHINE/Share\040with\040Spaces /media/winshares smbfs auto,credentials=/etc/smbcredentials,workgroup=MSHOME,gid=smb,uid=1000,fmask=770,dmask=770,rw 0 0
Testing fstab
Type the following to test our automatic Samba mounts.
$ sudo mount -a -t smbfs $ mount | grep smbfs
Your Samba share should be listed. It should also be accessible and have the correct permissions. If it does not, I suggest you review the previous steps.
Congratulations
Your shares should be working perfectly now, secure and reliable. The shares should appear in your filesystem at boot-up automatically.
Troubleshooting
If you get an error like this:
mount: wrong fs type, bad option, bad superblock on //DEVMACHINE/SHARE, missing codepage or helper program, or other error In some cases useful info is found in syslog - try dmesg | tail or so
You probably did not install the package smbfs.
$ sudo apt-get install smbfs
Please add any errors and solutions to them that you may find. -- This guide uses smbfs rather than cifsfs for mounting. smbfs has been unmaintained for years and is slated for removal from the kernel. -- JelmerVernooij