Saturday, September 23, 2017

Samba file sharing with user and group permissions in CentOS

Samba Installation

# yum install samba samba-client samba-common
Installed:
  samba.x86_64 0:3.6.23-42.el6_9      samba-client.x86_64 0:3.6.23-42.el6_9

Updated:
  samba-common.x86_64 0:3.6.23-42.el6_9

Dependency Updated:
  libsmbclient.x86_64 0:3.6.23-42.el6_9
  samba-winbind.x86_64 0:3.6.23-42.el6_9
  samba-winbind-clients.x86_64 0:3.6.23-42.el6_9

Complete!

# mkdir /samba /samba/shares
# touch testfile
# ls
testfile


#system-config-firewall-tui
 - customize-make sure  *samba *samba client save

# vi /etc/samba/smb.conf
#edit following parameters
[global]
workgroup=WORKGROUP
security = share

[Myshare]
path=/samba/shares
browsable=yes
writable=yes
valid users=windows

# useradd windows
# passwd windows
passwd: all authentication tokens updated successfully.

# smbpasswd -a windows
New SMB password:
Retype new SMB password:
Added user windows.

# testparm
Load smb config files from /etc/samba/smb.conf
rlimit_max: increasing rlimit_max (1024) to minimum Windows limit (16384)
Processing section "[homes]"
Processing section "[printers]"
Processing section "[Myshare]"
WARNING: The security=share option is deprecated
Loaded services file OK.
Server role: ROLE_STANDALONE
Press enter to see a dump of your service definitions

[global]
        server string = Samba Server Version %v
        security = SHARE
        log file = /var/log/samba/log.%m
        max log size = 50
        client signing = required
        idmap config * : backend = tdb
        cups options = raw

[homes]
        comment = Home Directories
        read only = No
        browseable = No

[printers]
        comment = All Printers
        path = /var/spool/samba
        printable = Yes
        print ok = Yes
        browseable = No

[Myshare]
        path = /samba/shares
        valid users = windows
        read only = No

# /sbin/service smb status
smbd is stopped
# service smb start
Starting SMB services:                                     [  OK  ]
# /sbin/service smb status
smbd (pid  2366) is running...

# /sbin/service nmb status
nmbd is stopped
# service nmb start
Starting NMB services:                                     [  OK  ]

Now go to your windows PC

//192.168.1.106

enter credential -  windows/smbwindows password  (here you not able to update files)

# cd /samba/
[root@localhost samba]# ls -l
total 4
drwxr-xr-x 2 root root 4096 May 10 23:23 shares
[root@localhost samba]# chmod -R 777 shares/
[root@localhost samba]# ls -l
total 4
drwxrwxrwx 2 root root 4096 May 10 23:23 shares

Adding one more folder and permissions

[root@localhost samba]# ls
shares
[root@localhost samba]# mkdir /samba /samba/Accounts
mkdir: cannot create directory `/samba': File exists
[root@localhost samba]# ls
Accounts  shares
[root@localhost samba]# ls -lah
total 16K
drwxr-xr-x   4 root root 4.0K May 11 17:02 .
dr-xr-xr-x. 24 root root 4.0K May 11 16:55 ..
drwxr-xr-x   2 root root 4.0K May 11 17:02 Accounts
drwxrwxrwx   2 root root 4.0K May 10 23:23 shares
[root@localhost samba]# chown -R windows shares
[root@localhost samba]# ls -lah
total 16K
drwxr-xr-x   4 root    root 4.0K May 11 17:02 .
dr-xr-xr-x. 24 root    root 4.0K May 11 16:55 ..
drwxr-xr-x   2 root    root 4.0K May 11 17:02 Accounts
drwxrwxrwx   2 windows root 4.0K May 10 23:23 shares

[root@localhost samba]# vi /etc/samba/smb.conf
[IT]
path=/samba/shares
browsable=yes
writable=yes
valid users=windows

[Accounts]
path=/samba/Accounts
browsable=yes
writable=yes
valid users=accounts


[root@localhost samba]# useradd accounts
[root@localhost samba]# passwd accounts
Changing password for user accounts.
New password:
BAD PASSWORD: it is based on a dictionary word
Retype new password:
passwd: all authentication tokens updated successfully.
[root@localhost samba]# smbpasswd -a accounts
New SMB password:
Retype new SMB password:
Added user accounts.

[root@localhost samba]# ls -lah
total 16K
drwxr-xr-x   4 root    root 4.0K May 11 17:02 .
dr-xr-xr-x. 24 root    root 4.0K May 11 16:55 ..
drwxr-xr-x   2 root    root 4.0K May 11 17:02 Accounts
drwxrwxrwx   2 windows root 4.0K May 10 23:23 shares
[root@localhost samba]# chown -R accounts Accounts
[root@localhost samba]# ls -lah
total 16K
drwxr-xr-x   4 root     root 4.0K May 11 17:02 .
dr-xr-xr-x. 24 root     root 4.0K May 11 16:55 ..
drwxr-xr-x   2 accounts root 4.0K May 11 17:02 Accounts
drwxrwxrwx   2 windows  root 4.0K May 10 23:23 shares


[root@localhost samba]# service smb restart
Shutting down SMB services:                                [  OK  ]
Starting SMB services:                                     [  OK  ]
[root@localhost samba]# service nmb restart
Shutting down NMB services:                                [  OK  ]
Starting NMB services:                                     [  OK  ]


Details about chmod

-rw------- (600) Only the owner has read and write permissions.
-rw-r--r-- (644) Only the owner has read and write permissions; the group and others have read only.
-rwx------(700) Only the owner has read, write, and execute permissions.
-rwxr-xr-x(755) The owner has read, write, and execute permissions; the group and others have only read and execute.
-rwx--x--x(711) The owner has read, write, and execute permissions; the group and others have only execute.
-rw-rw-rw-(666) Everyone can read and write to the file. (Be careful with these permissions.)
-rwxrwxrwx(777) Everyone can read, write, and execute. (Again, this permissions setting can be hazardous.)

User and Group Permission

[root@localhost samba]# groupadd aadhar
[root@localhost samba]# cat /etc/group
ttadmin:x:500:
windows:x:501:
accounts:x:502:
aadhar:x:503:
[root@localhost samba]# cat /etc/passwd
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin
ttadmin:x:500:500::/home/ttadmin:/bin/bash
windows:x:501:501::/home/windows:/bin/bash
accounts:x:502:502::/home/accounts:/bin/bash

[root@localhost samba]# usermod -G aadhar windows
[root@localhost samba]# cat /etc/passwd
ttadmin:x:500:500::/home/ttadmin:/bin/bash
windows:x:501:501::/home/windows:/bin/bash
accounts:x:502:502::/home/accounts:/bin/bash

[root@localhost samba]# cat /etc/group
ttadmin:x:500:
windows:x:501:
accounts:x:502:
aadhar:x:503:windows



[root@localhost samba]# ls -lah
total 16K
drwxr-xr-x   4 root     root 4.0K May 11 17:02 .
dr-xr-xr-x. 24 root     root 4.0K May 11 16:55 ..
drwxr-xr-x   3 accounts root 4.0K May 11 17:19 Accounts
drwxrwxrwx   2 windows  root 4.0K May 10 23:23 shares

[root@localhost samba]# chown -R accounts:aadhar Accounts

[root@localhost samba]# ls -lah
total 16K
drwxr-xr-x   4 root     root   4.0K May 11 17:02 .
dr-xr-xr-x. 24 root     root   4.0K May 11 16:55 ..
drwxr-xr-x   3 accounts aadhar 4.0K May 11 17:19 Accounts
drwxrwxrwx   2 windows  root   4.0K May 10 23:23 shares

No comments:

Post a Comment