[转]Install Samba Server on Ubuntu

If you want to share files between your Ubuntu and Windows computers, your best option is to use Samba file sharing.

To install, first open a terminal window and enter the following command:

    sudo apt-get install samba smbfs

We’ve got samba installed, but now we’ll need to configure it to make it accessible. Run the following command to open the configuration file, substituting your editor of choice:

    sudo gedit /etc/samba/smb.conf

Find this section in the file:

    ####### Authentication #######
 
    # "security = user" is always a good idea. This will require a Unix account
    # in this server for every user accessing the server. See
    # /usr/share/doc/samba-doc/htmldocs/Samba-HOWTO-Collection/ServerType.html
    # in the samba-doc package for details.
    ;  security = user

Uncomment the security line, and add another line to make it look like this:

    security = user
    username map = /etc/samba/smbusers

This will set Samba to use the smbusers file for looking up the user list.

Create a Samba User

There are two steps to creating a user. First we’ll run the smbpasswd utility to create a samba password for the user.

    sudo smbpasswd -a <username>
</username>

Next, we’ll add that username to the smbusers file.

    sudo gedit /etc/samba/smbusers

Add in the following line, substituting the username with the one you want to give access to. The format is = ““. You can use a different samba user name to map to an ubuntu account, but that’s not really necessary right now.

    <username> = "</username><username>"
</username>

Now you can create samba shares and give access to the users that you listed here.

How do I set permissions to Samba shares?

Samba Basic permissions are as follows (configuration file is smb.conf [/etc/samba/smb.conf]):

* read only : This parameter controls whether an user has the ability to create or modify files within a share. This is default.
* guest ok : Uf this parameter is set to yes, the users will have access to the share without
having to enter a password. This can pose security risk.
* writeable : Specifies users should have write access to the share.

You can create the share called helpfiles with read only permission

[helpfiles]
path = /usr/share/docs
read only = Yes

You can create the share called salesdoc with write permission

[salesdoc]
path = /home/shared/sales
writeable = Yes

You can also create a list of users to give write access to the share with write list option. For example allow rocky and tony to write to the share called sales:

[salesdoc]
path = /home/shared/sales
write list = rocky tony

You can use following options

* read list : This option accepts a list of usernames or a group as its value. Users will be given read-only access to the share.
* valid users : You can make a share available to specific users. Usernames or group names can be passed on as its value.
* invalid users : Users or groups listed will be denied access to this share.

Samba mask permission

It is also possible to specify samba default file creation permission using mask.

* create mask : This option is set using an octal value when setting permissions for files.
* directory mask : Directories must have the execute bit for proper access. Default parameter is 0755.

[salesdoc]
path = /home/shared/sales
write list = rocky sys
create mask = 0775

At the end, please run the command:

    sudo /etc/init.d/samba reload

to reload the config file or run command:

    sudo /etc/init.d/samba restart

to restart the server.

此条目发表在 linux/server 分类目录。将固定链接加入收藏夹。

发表评论

电子邮件地址不会被公开。 必填项已用*标注

您可以使用这些HTML标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>