Most of the documentation on this page has been taken from the CentOS wiki.
For every commands below, you must be logged in as root. To do so, use this command:
sudo su
Configurations
To mount locally a SMB share on your server, you will need to install some packages. To do so, use this command:
yum install samba-client samba-common cifs-utils autofs
You can then create a mount point in your server. To do so, use this command:
mkdir /mnt/{nameOfMount}
Where {nameOfMount} is the name that you want the mount point to have.
Manually mount
To manually mount the share, you can use this command:
mount -t cifs -o user,rw,username={username},password={password} {host}/{sharePath} /mnt/{nameOfMount}
Where:
- {username} is the username of the share.
- {password} is the password of the share.
- {host} is the host of the share that you want to mount. An example would be //10.10.10.10.
- {sharePath} is the path of the share that you want to mount. An example would be example.
- {nameOfMount} is the name that was given to the mount point in the previous section.
Automatically mount on boot
To automatically mount the share on boot, you will need to add a new line in the /etc/fstab file. To do so, use this command:
vi /etc/fstab
Using the opened file editor, copy the following into it:
{host}/{sharePath} /mnt/{nameOfMount} cifs user,rw,username={username},password={password} 0 0
Where:
- {host} is the host of the share that you want to mount. An example would be //10.10.10.10.
- {sharePath} is the path of the share that you want to mount. An example would be example.
- {nameOfMount} is the name that was given to the mount point in the previous section.
- {username} is the username of the share.
- {password} is the password of the share.
Once this is done, save the file. You can then run the following command to test whether the mount is working or not:
mount -a
This command will mount the share that you set up. Once this is done, it will automatically mount on boot.
Mount multiple shares dynamically
The shares must have the same username and password.
You need to use a credential file for this one. To do so, use this command:
vi /root/secret.txt
This will create a file to put your username and password in it. In the opened file editor, copy the following:
username={username} password={password}
Where:
- {username} is the username of the shares.
- {password} is the password of the shares.
Once this is done, save the file.
You will need to add a line to the /etc/auto.master. To do so, use this command:
vi /etc/auto.master
In the opened file editor, copy the following:
/mnt/{nameOfMount} /etc/auto.smb.top
Where {nameOfMount} is the name that was given to the mount point in the previous section. Once this is done, save the file.
You will need to create the /etc/auto.smb.top file and add text to it. To do so, use this command:
vi /etc/auto.smb.top
In the opened file editor, copy the following:
* -fstype=autofs,-Dhost=& file:/etc/auto.smb.sub
Once this is done, save the file.
You will need to create the /etc/auto.smb.sub file and add text to it. To do so, use this command:
vi /etc/auto.smb.sub
In the opened file editor, copy the following:
* -fstype=cifs,credentials=/root/secret.txt ://${host}/&
Finally, you will need to adjust the permission to the new files and restart the autofs service. To do so, use these commands:
chmod 644 /etc/auto.smb.* /sbin/service autofs restart
Once this is done, you should be able to access the mounted shares with this command:
cd /mnt/{nameOfMount}/{sharePath}
Where:
- {nameOfMount} is the name that was given to the mount point in the previous section.
- {sharePath} is the path of the share on the host.
Note that a sharePath with spaces in it will not work.
Comments
0 comments
Article is closed for comments.