Scenario:
-Mount Windows Folder Sharing (CIFS) on RHEL 6/CentOS 6.
-Set only Linux user >> user1 that have RWX access.
-Hide sharing credentials from other Linux users.
-Mount permanent at boot.
System: CentOS 6
Steps:
1) Edit /etc/fstab
# vi /etc/fstab
2) Type mount command in fstab.
Note: By default windows share mounted with the full permission (777) in Linux. To change the default permission use the dir_mode and file_mode options to set directory and file permission.
//WIN_PC_IP/[share name] /[mount point] cifs _netdev,credentials=/root/.filepassw,password>,dir_mode=0755,file_mode=0755,uid=500,gid=500 0 0
in this scenario,only Linux user user1 have read write access on /winshare.
//192.168.99.10/LINUX /winshare cifs _netdev,credentials=/root/.winpasw,dir_mode=0700,file_mode=0700,uid=user1,gid=user1 0 0
3) Create folder sharing credential file.
# touch /root/.winpasw
username=srvlinux
password=mypassword
domain=toya.example.com
4) Run mount command to /winshare
# mount -a
Test Result:
login as: user1
user1@192.168.99.15's password:
Last login: Sun Oct 31 11:09:45 2017 from 192.168.99.99
[user1@svrtest ~]$ cd /winshare/
[user1@svrtest winshare]$ mkdir okttest
[user1@svrtest winshare]$ ls
oke okttest folder test
[user1@svrtest winshare]$ su test
Password:
[test@svrtest winshare]$ ls
ls: cannot open directory .: Permission denied
[test@svrtest winshare]$ cd /
[test@svrtest /]$ cd /winshare/
bash: cd: /winshare/: Permission denied
[test@svrtest /]$
How to temporary mount Windows File sharing and moount to a directory
# mkdir /WinFolder
# mount -t cifs -o username=myusername,password=mypassword,domain=my.domain.com //192.168.2.5/folder /WinFolder
How to umount and delete directory
# umount /WinFolder
# rm -rf /WinFolder