Tuesday, April 26, 2016

Setting up SAMBA server


  • Accessing samba share
    • smbclient -L //localhost
    • smbclient -U erick //localhost/data
  • Mounting samba share
    • yum -y install cifs-utils
      • mount -o username=erick //localhost/share /mnt
  • Installation
    • yum -y install samba samba-client
    • systemctl start smb nmb
    • systemctl enable smb nmb
    • firewall-cmd --permanent --add-service=samba
    • firewall-cmd --reload
  • Creating share with read access from specific user, changing workgroup and allowing specific network.
    • Create linux and samba user <-- linux user should exist first, before creating samba user.
      • useradd -s /sbin/nologin erick
      • smbpasswd -a erick
    • mkdir /sambashare
      • semanage fcontext -a -t samba_share_t "/sambashare(/.*)?"
      • restorecon -R -v /sambashare
      • setfacl -m u:erick:r-X /sambashare
      • getfacl /sambashare
    • vim /etc/samba/smb.conf
[global]
workgroup = TESTGROUP

[data]
        comment = data
        path = /sambashare
        browseable = yes
        writable = yes
        valid users = erick
        read only = yes
        hosts allow = 192.168.23.
    • systemctl restart smb
    • testparm <--checking configuration
    • smbclient -U erick //localhost/data <--test
  • Creating share with read/write and read access from multiple user.
    • Create linux and samba user <-- linux user should exist first, before creating samba user.
      • useradd -s /sbin/nologin dimple
      • useradd -s /sbin/nologin andrei
      • smbpasswd -a dimple
      • smbpasswd -a andrei
    • mkdir /sambashare2
      • semanage fcontext -a -t samba_share_t "/sambashare2(/.*)?"
      • restorecon -R -v /sambashare2
      • setfacl -m u:dimple:rwX /sambashare2
      • setfacl -m u:andrei:r-X /sambashare2
      • getfacl sambashare2
    • vim /etc/samba/smb.conf
[data2]
        comment = data2
        path = /sambashare2
        browseable = yes
        writable = yes
        valid users = dimple andrei
        read only = no

    • systemctl restart smb
    • testparm <--checking configuration
    • to test
      • yum -y install cifs-utils
      • mount -o username=dimple //localhost/data2 /dimple
        • user dimple should have rwx permission to data2
[root@server2 dimple]# df -h .
Filesystem         Size  Used Avail Use% Mounted on
//localhost/data2   18G  4.2G   14G  24% /dimple
[root@server2 dimple]# touch dimple.txt
[root@server2 dimple]# ls -l dimple.txt
-rw-r--r--. 1 dimple dimple 0 Apr 26 12:13 dimple.txt
      • mount -o username=andrei //localhost/data2 /andrei
        • user andrei should have read only access to data2
[root@server2 andrei]# df -h .
Filesystem         Size  Used Avail Use% Mounted on
//localhost/data2   18G  4.2G   14G  24% /andrei
[root@server2 andrei]# touch andrei.txt
touch: cannot touch ‘andrei.txt’: Permission denied

  • SMB multiuser mount
    • yum -y install cifs-utils
    • mkdir -p /mnt/sambashare
    • vim /root/smb-multiuser.txt
      • username=dimple
      • password=123456
    • chmod 0600 /root/smb-multiuser.txt
    • vim /etc/fstab
      • //server2/data2 /mnt/sambashare cifs defaults,sec=ntlmssp,credentials=/root/smb-multiuser.txt,multiuser 0 0
[root@server3 sambashare]# df -h .
Filesystem       Size  Used Avail Use% Mounted on
//server2/data2   18G  4.2G   14G  24% /mnt/sambashare
[root@server3 sambashare]# ls -l
total 4
-rw-r--r--. 1 1001 1001 17 Apr 26 12:19 dimple.txt
-rw-r--r--. 1 1001 1001  0 Apr 26 12:26 sample.txt

No comments:

Post a Comment