Monday, 30 January 2012

Install and configure samba

1. Install samba using yum
$ yum install samba

2. open samba configuration /etc/samba/smb.conf and change the below lines

workgroup = WORKGROUP   # The workgroup of windows and linux should be same
hosts allow = 192.168.1.            # Only 192.168.1. host can access the share

# You can create the share called files with read only permission
path = /usr/share/docs
read only = Yes

# You can create the share called sales with write permission
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 bob and jay to write to the share called sales:
path = /home/shared/sales
write list = bob jay

# Public folder for all
# drwxrwxr-x  root staff  /home/samba/public
comment = Public Stuff
path = /home/samba/public
read only = Yes
write list = @staff
guest ok = Yes
create mask = 0664
directory mask = 0775

This will make the files readable to everyone and writable only by "staff". The "create mask" and "directory mask" ensure new and modified files and directories retain their correct permissions.

# Folder with only certain groups can browse only
# drwxrwx---  root mygroup  /home/samba/sharing
comment = people stuff
path = /home/samba/sharing
valid users = @mygroup
public = no
writable = yes
printable = no
create mask = 0660
directory mask = 0770

This share will now only be accessable to members of "mygroup". The "create mask" and "directory mask" ensure new and modified files and directories retain their correct permissions.

The create mask sets the permissions that files will be created with by an SMB client. Directory mask sets the permissions that directories will be created with.


[ 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.

* 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.

security = share
If it is set to security = user it will ask for a password to authenticate.]

3. Create samba user password
$ smbpasswd -a username

4. set selinux to permissive mode
$ setenforce 0
$ getenforce

5. Optional: If there is any issue with read/write to the share folder, issue the following command
$ chcon -R -t samba_share_t /home/folder/Share

6. check the share is available on its own computer:
$ smbclient -U username -L IP
$ smbclient -U username //IP/foldername

7. check the status
$ smbstatus

8. Restart samba service
$ /etc/init.d/smb restart

In windows, start run and type \\IP . A login prompt will appear and enter the password. To logout the session from windows, type the following command in CMD

>net use * /Del  

No comments:

Post a Comment