How to Mount SMB Shares on CentOS 7
How to Mount SMB Shares on CentOS 7
-
Install the cifs-utils package from the default CentOS yum repository.
sudo yum install cifs-utils -
Next, we need an account on the CentOS server that will map to the Windows account granted permission to the SMB share, sharelibrarycore. We’ll create a service account named svclibrarycore with a user id (UID) of 5000. We also want a group on the CentOS server that will map to the share. This group will contain all of the Linux accounts that will need access to the share. Our account will be called sharelibrarycore and it will have a group id (gid) of 6000. Finally, add any Linux accounts that require access to the SMB share to the newly created Linux group. I have an existing account named user1 that I will add to the sharelibrary_core group.
sudo useradd -u 5000 flink_smb_user sudo groupadd -g 6000 smb_users sudo usermod -G smb_users -a mashintsev sudo usermod -G smb_users -a parsersapp -
Create a directory to mount the SMB share into. We’ll mount the share in a directory called lib_core.
sudo mkdir /mnt/vmcollector2 -
Using the mount.cifs command, mount the SMB share into libcore using the Active Directory user account _sharelibrarycore. We need to map the UID of our svclibrarycore account (5000) and the gid of our sharelibrary_core group (6000) to the SMB share.
sudo mount.cifs \\\\VMCOLLECTOR2\\DataIn /mnt/vmcollector2 -o user=i.mashintsev-adm,pass="",uid=5000,gid=6000 -
Create a credentials file in Root’s home directory. I typically create this file in a sub-directory in Root’s home, for organizational reasons. But for this example, I will place it in /root.
sudo touch /root/creds_vmcollector2 -
Modify the file’s permissions so that only the Root account is granted read permissions. No groups or other users should have access to the file.
sudo chmod 0600 /root/creds_vmcollector2 -
Open the file in a text editor. I like using VI, but you can use whichever you prefer.
sudo vi /root/creds_vmcollector2 -
Mount the SMB share. However, instead of using the user and pass options, we instead use the credentials option and point to our credentials file.
sudo mount.cifs \\\\VMCOLLECTOR2\\DataIn /mnt/vmcollector2 -o credentials=/root/creds_vmcollector2,uid=5000,gid=6000 -
Open /etc/fstab into a text editor.
vi /etc/fstab -
Add the following line to your fstab. Remember to replace the values with those that match your environment.
//VMCOLLECTOR2/DataIn /mnt/vmcollector2 cifs credentials=/root/creds_vmcollector2,uid=5000,gid=6000 0 0 -
The SMB share will mount the next time the CentOS server is rebooted. To mount the share immediately, use the mount command.
mount -a